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;
                }
            }
        }
    }

  • 相关阅读:
    servlet和springMVC框架
    JavaWeb登录、注销、退出、记住用户名和密码-session
    一个实现用户登录注销的小程序,求大神帮忙解救 ...
    log4j:WARN Please initialize the log4j system properly解决办法
    接上一篇
    Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds...
    classpath
    跳转页面代码
    程序猿学习路线
    Calendar
  • 原文地址:https://www.cnblogs.com/mane/p/2098274.html
Copyright © 2011-2022 走看看