zoukankan      html  css  js  c++  java
  • 简单的asp.net文件上传类

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI.WebControls;

    namespace WebSite
    {
        public class SendFile
        {
            /// <summary>
            /// 文件上传方法
            /// </summary>
            /// <param name="allowFileType">允许上传的类型,中间用","隔开</param>
            /// <param name="maxFileSize">允许上传的最大尺寸</param>
            /// <param name="fileUploadPath">上传到的目录</param>
            /// <param name="file">使用的FileUpload上传控件</param>
            /// <returns>返回文件名称</returns>
            public static string sendFileUpload(string allowFileType, int maxFileSize, string fileUploadPath, FileUpload file)
            {
                if (file.HasFile)//判断FileUpload是否有需要上传的文件
                {
                    string fileName = file.FileName;//文件名
                    string fileType = System.IO.Path.GetExtension(fileName);//文件类型
                    int fieSize = (int)file.FileContent.Length;//文件大小
                    if (allowFileType.LastIndexOf(fileType) > -1 && fieSize < maxFileSize)//判断文件类型和大小
                    {
                        file.PostedFile.SaveAs(fileUploadPath + fileName);//上传文件
                        return fileName;//返回文件名
                    }
                    else
                    {
                        return null;
                    }
                   
                }
                else
                {
                    return null;
                }
            }
        }
    }

  • 相关阅读:
    安装python模块时出现:error: Setup script exited with error: command 'gcc' failed with exit status 1
    Thunderbird设置邮件回复时自动签名和邮件引用的位置
    php脚本获取管道的输入数据
    xx is not in the sudoers file
    ubuntu快捷键设置
    (一) solr的安装与配置
    经典地址收集
    VS 2008如何连接TFS 2010
    SQL Server判断对象是否存在(整理中...)
    C++] WAP GPRS 向WWW网站 提交POST GET 数据 实例
  • 原文地址:https://www.cnblogs.com/mane/p/2098274.html
Copyright © 2011-2022 走看看