zoukankan      html  css  js  c++  java
  • ASP.NET上传文件函数

    public static string fileUpladPost(string spath)
        {
            HttpFileCollection files = HttpContext.Current.Request.Files;

            StringBuilder strMsg = new StringBuilder();

            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFile f = files[i];

                string fileName = Path.GetFileName(f.FileName);

                if (fileName != String.Empty)
                {
                    string fileExtension = Path.GetExtension(fileName);
                    strMsg.Append("上传的文件类型:" + f.ContentType.ToString() + "<br>");
                    strMsg.Append("客户端文件地址:" + f.FileName + "<br>");
                    strMsg.Append("上传文件的文件名:" + fileName + "<br>");
                    strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");

                    f.SaveAs(HttpContext.Current.Server.MapPath(spath) + fileName);
                }
            }

            return strMsg.ToString();
        }
    //该函数可以处理POST过来的FILE,spath为存储路径

  • 相关阅读:
    每日作业
    Bootstrap框架
    每日作业
    前端之jQuery
    css之浮动详解
    sh命令
    shell编程:sed的选项
    linux 创建连接命令 ln -s 软链接
    grep与egrep命令
    Centos之命令搜索命令whereis与which
  • 原文地址:https://www.cnblogs.com/cosiray/p/1552703.html
Copyright © 2011-2022 走看看