读书人

asp.net中上传多个资料

发布时间: 2011-12-25 23:21:20 作者: rapoo

asp.net中上传多个文件
谁能给点多文件上传的例子,谢谢啦

[解决办法]

C# code
   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();     } 

读书人网 >.NET

热点推荐