C#上传图片 支持多张上传

protected void Page_Load(object sender, EventArgs e)
    {
        string filepath = Server.MapPath("~/Images") + "\\";   //要上传的文件夹的路径
        if (!Directory.Exists(filepath))  //不存在文件夹,创建
        {
            Directory.CreateDirectory(filepath);  //创建新的文件夹
        }
      
        HttpRequest request = System.Web.HttpContext.Current.Request;
        HttpFileCollection FileCollect = request.Files;
        for (int i = 0; i < FileCollect.Count; i++)
        {
            HttpPostedFile mypost = FileCollect[i]; //用key获取单个文件对象HttpPostedFile
            try
            {
                if (mypost.ContentLength > 0)
                {
                    string filename = mypost.FileName;  //通过此对象获取文件名
                    string serverpath = filepath + "\\" + filename;
                    mypost.SaveAs(serverpath);
                    Response.Write("success");
                    Response.End();
                }
            }
            catch (Exception)
            {
                throw;
            }
           
        }
     
        }

你可能感兴趣的:(C#上传图片 支持多张上传)