question

Anna-8164 avatar image
0 Votes"
Anna-8164 asked APoblacion answered

want to store many files by using array from dialog

want to store many files which is from dialog +


FileStream(@"F:\C#projects\abc1.0 txt",FileMode.OpenOrCreate,FileAccess.Read);

FileStream(@"F:\C#projects\abc2.txt",FileMode.OpenOrCreate,FileAccess.Read);

FileStream(@"F:\C#projects\abc3.txt",FileMode.OpenOrCreate,FileAccess.Read);

thanks

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

APoblacion avatar image
0 Votes"
APoblacion answered

If you are using the OpenFileDialog in Multiselect mode, it will return a property named FileNames with the full paths to all files. You can simply use a loop to iterate through the array:

 foreach (string filename in openFileDialog1.FileNames)
 {
     using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read)
     {
         // Here you do whatever you want with the Stream fs
     }
 }

Note: You didn't specify what you wanted to do with the file other than saying "store". If by "store" you mean making a copy of the file, the it is not necessary to open a FileStream (although you can if you wish); it is much simpler to just call File.Copy.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.