Multi file upload using c# on ASP.NET 4.0 environment

后端 未结 6 2095
死守一世寂寞
死守一世寂寞 2020-12-30 08:49

I am looking for a solution to upload multiple files (click on browse button, and select multiple files using shift key).

I see several solutions that need to be upl

6条回答
  •  余生分开走
    2020-12-30 09:34

    Set the property "AllowMultiple = true" as below. This property is available for 4.5 framework.

     
    

    This will allow you to select multiple files at one time

    Aspx Code:

    Aspx.cs Code:

    protected void btnFileUpload_Click(object sender, EventArgs e)
    {
        try
        {
            if (file_upload.HasFile && file_upload.PostedFiles.All(x => x.ContentType == "image/jpeg" && x.ContentLength < 102400))
            {
                foreach (var file in file_upload.PostedFiles)
                {
                    file_upload.SaveAs(Server.MapPath("~/") + Path.GetFileName(file.FileName));
                }
                lblUploadStatus.Text = "File(s) uploaded successfully.";
            }
            else
            {
                lblUploadStatus.Text = "Please upload proper file.";
            }
        }
        catch (Exception ex)
        {
            lblUploadStatus.Text = "Error in uploading file." + ex.Message;
        }
    }
    

提交回复
热议问题