0

I have a webpage(.aspx) which contains MULTIPLE FileUpload controls.

Default.aspx

<asp:FileUpload ID="FileUploadPort" runat="server" CssClass="Upload"  Multiple="Multiple"/>
<asp:FileUpload ID="FileUploadSearchImages" runat="server" CssClass="Upload"  Multiple="Multiple"/>

Default.aspx.cs

protected void btnSubmit_Click(object sender, EventArgs e)
{
       string filenm = string.Empty;
       HttpFileCollection fileCollection = Request.Files;
       for (int i = 0; i < fileCollection.Count; i++)
       {
           HttpPostedFile uploadfile = fileCollection[i];
           if (uploadfile.ContentLength > 0)
            {
              string filename = uploadfile.FileName;
              string imgFolder = ConfigurationManager.AppSettings["AdminSearchImgFolderPath"];
              System.Drawing.Image image = System.Drawing.Image.FromStream(uploadfile.InputStream); 
              image.Save(imgFolder + "\\" + GetSearchImageFileName("TEST"), ImageFormat.Jpeg);

             }
        }
    }

Here, Request.Files will get collectively all files from both the FileUploadControls.

I am NOT able to IDENTIFY which file(s) are from specific FileUpload control?

I know its possible in 4.5 but my current framework is 4.0 and i dont want to upgrade to 4.5. Any solution using existing 4.0 framework??

Help appreciated!

Please note: This is not DUPLICATE question as my requirement is to upload and identify the files of different fileupload controls on single page.

SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143
  • Use if (FileUploadPort.HasFiles) to determine if the control has files and then continue to save the files. The process you can implement for the other fileupload control. This way you are able to identify which files are from a specific fileupload control. – Kami Apr 18 '16 at 14:12
  • This i have tried but how to get/iterate to files of specific fileupload control? Will you please post some code here...????? – SHEKHAR SHETE Apr 19 '16 at 04:07
  • Use this link. http://www.aspsnippets.com/Articles/Upload-multiple-files-with-ASPNet-45-FileUpload-control-in-Visual-Studio-2012-and-2013.aspx – Kami Apr 19 '16 at 14:18
  • Please read the post carefully. I have mentioned i am using 4.0 and not 4.5 framework :( – SHEKHAR SHETE Apr 20 '16 at 06:07
  • :) Ok, Take a look at this link, that might work for you. http://www.codeproject.com/Articles/667604/Upload-multiple-files-in-asp-net – Kami Apr 20 '16 at 13:29
  • Possible duplicate of [How to choose multiple files using File Upload Control?](https://stackoverflow.com/questions/17441925/how-to-choose-multiple-files-using-file-upload-control) – Naveen Gogineni May 30 '17 at 10:04
  • Please read the question carefully..! it is 'Multiple file upload using multiple File Upload Controls' not single 'FileUpload control' – SHEKHAR SHETE May 31 '17 at 06:15

1 Answers1

0

You can add an extension method to get the same effect as .Net 4.5 as in this answer:

https://stackoverflow.com/a/30360786

[ note: I can't comment that's why i posted this as an answer ]

Muayyad Diab
  • 88
  • 2
  • 10