c# 添加多个文件到列表

标签 c# asp.net .net webforms

我正在编写一个简单的代码,使用单个上传按钮 (AllowMultiple="true") 上传多个文件,我正在尝试将所有上传的文件添加到列表中,但问题是仅添加第一个文件,不添加其他文件。

asp.net

<asp:FileUpload runat="server" ID="file1" AllowMultiple="true" />

c#

PdfReader pdfReader1 = new PdfReader(file1.PostedFile.InputStream);
List<PdfReader> readerList = new List<PdfReader>();
readerList.Add(pdfReader1);

最佳答案

使用 PostedFile 你只能得到一个项目,使用 PostedFiles 代替:

List<PdfReader> readerList = new List<PdfReader>();
readerList.AddRange(file1.PostedFiles.Select(f=>new PdfReader(f.InputStream)))

关于c# 添加多个文件到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42648440/

相关文章:

c# - 发送电子邮件的 SMTP 错误?

C# IDisposable问题

c# - 字符串的双引号问题

Asp.Net Signal R - 检测数据库中的变化? Asp.net 网页表单

c# - 哪个是更好的选择? - 在 Web 控件的 Viewstate 中的局部变量或存储变量

c# - 为什么不能通过实例名称访问静态成员?

c# - 如何评论公开可见的类型枚举?

c# - MVC 中 RadioButtonFor 的回发

asp.net - 我能否从网站代码中检测 ASP.NET 网站是否启用了 SSL/https?

.net - Visual Studio 2010 : Properties. 将项目重定向到 .NET Framework 3.5 后设置损坏