首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

asp.net中下传多个文件

2012-12-24 
asp.net中上传多个文件谁能给点多文件上传的例子,谢谢啦[解决办法]public static stringCreateUploadFile(

asp.net中上传多个文件
谁能给点多文件上传的例子,谢谢啦
[解决办法]

   public static string  CreateUploadFile(string FileOlder)
    {
      
         HttpPostedFile postedfile;

        HttpFileCollection file1 = HttpContext.Current.Request.Files;

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
        st.Start();
        for (int i = 0; i < file1.Count; i++)
        {
            postedfile = HttpContext.Current.Request.Files[i];

            //获取文件的扩展名
             FileEx=Path.GetExtension(postedfile.FileName);

            //追加文件名
           

            ////定义文件名以时间命名加上文件扩展名
             string saveFile= DateTime.Now.ToString("yyyyMMddHHmmss")+st.ElapsedTicks.ToString() + FileEx;
             sb.Append(saveFile);
             sb.Append(",");

            //保存文件
             postedfile.SaveAs(HttpContext.Current.Server.MapPath(FileOlder + "/") + saveFile);

        }
        if(sb.Length>0)
        sb.Remove(sb.Length-1, 1);
   
        st.Stop();

        return sb.ToString();
 
    }

热点排行