want to store many files by using array from dialog

Anna 1 Reputation point
2021-04-11T13:12:14.943+00:00

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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,279 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Poblacion 1,566 Reputation points
    2021-04-11T17:44:23.74+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.