1

I am working on a simple code to upload multiple files using single upload button (AllowMultiple="true"), and I am trying to add all the uploaded files to list, but the problem is only the first file is added without the other files.

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);
Maksim Simkin
  • 9,561
  • 4
  • 36
  • 49
azza
  • 77
  • 1
  • 10
  • That's because you have added one reader to you reader list. You probably want to read files with reader. – Renatas M. Mar 07 '17 at 12:37
  • Maybe this will help: http://stackoverflow.com/questions/17441925/how-to-choose-multiple-files-using-file-upload-control – Mighty Badaboom Mar 07 '17 at 12:38
  • First, AllowMultiple="true" is a .Net 4.5 property. Are you sure to have it ? Below 4.5 it was something like Multiple="Multiple" (check on the MSDN). Second : you have to use the file1.PostedFiles collection to retrieve all files. – AFract Mar 07 '17 at 12:38

1 Answers1

3

With PostedFile you get only one item, use PostedFiles instead:

List<PdfReader> readerList = new List<PdfReader>();
readerList.AddRange(file1.PostedFiles.Select(f=>new PdfReader(f.InputStream)))
Maksim Simkin
  • 9,561
  • 4
  • 36
  • 49