来自2个或更多文件上传控件的多个文件 [英] Multiple files from 2 or more file upload controls

查看:85
本文介绍了来自2个或更多文件上传控件的多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dears,



我在这里从asp.net mvc中的多个控件上传多个文件的情况。



我如何区分(分组)每个文件上传控件的文件?



在HTML中:

这是上传者:

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:

<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>




$服务器端的b $ b:



in server side:

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.

推荐答案

使用 HttpFileCollectionBase.GetMultiple [ ^ ]检索已发布文件的列表对于每个输入:

Use HttpFileCollectionBase.GetMultiple[^] to retrieve the list of posted files for each input:
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.


确定这不起作用:

Pretty sure this won't work:
FileContent = data

由于 data 在循环内没有改变,你将获得每个文件的相同文件内容(如果有的话)。我认为您需要访问file.Content Stream才能使用它...

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...


这篇关于来自2个或更多文件上传控件的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆