Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dears,

I 've a situation here in uploading multiple files from multiple controls in asp.net mvc.

How can i differentiate (grouping) between files of each file upload controls?

In HTML:
Here is the uploaders:
HTML
<input type="file" name="AdditionalDocs" class="form-control" id="AdditionalDocs" multiple>

<input type="file" name="BudgetDocs" class="form-control" id="BudgetDocs" multiple>

<input type="file" name="TimelineDocs" class="form-control" id="TimelineDocs" multiple>


in server side:
C#
for (int i = 0; i < Request.Files.Count; i++)
{
    HttpPostedFileBase file = Request.Files[i];
    if (file.ContentLength > 0)
    {        
        lstAttachments.Add(new AttachmentDTO
        {
            FileName = file.FileName,
            MimeType = file.ContentType,
            FileContent = data
        });               
    }
}


After that i got all files but not categprized.

Any Ideas to categorize these files?

What I have tried:

I tried depending on file name while categorizing these files but may be the file name is repeated.
Posted
Updated 2-Nov-18 5:55am

Use HttpFileCollectionBase.GetMultiple[^] to retrieve the list of posted files for each input:
C#
IList<HttpPostedFileBase> additionalDocs = Request.Files.GetMultiple("AdditionalDocs");
IList<HttpPostedFileBase> budgetDocs = Request.Files.GetMultiple("BudgetDocs");
IList<HttpPostedFileBase> timelineDocs = Request.Files.GetMultiple("TimelineDocs");
You can then process the files from each list separately.
 
Share this answer
 
Pretty sure this won't work:
FileContent = data
Since data doesn't change inside your loop, you will get the same file content (if any) for every file. I think you need to access the file.Content Stream in order to use it...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900