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.

7
  • 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. Commented Apr 18, 2016 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...????? Commented Apr 19, 2016 at 4:07
  • Use this link. aspsnippets.com/Articles/… Commented Apr 19, 2016 at 14:18
  • Please read the post carefully. I have mentioned i am using 4.0 and not 4.5 framework :( Commented Apr 20, 2016 at 6:07
  • :) Ok, Take a look at this link, that might work for you. codeproject.com/Articles/667604/… Commented Apr 20, 2016 at 13:29

1 Answer 1

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 ]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.