Is it possible to parse the stream? That is, to obtain from it the name of the file, the path to the file, and so what lies in the file (as text of course)?

  • If you are given an exhaustive answer, mark it as correct (tick the selected answer). - andreycha

1 answer 1

In general, there is no such information in the streams. These entities provide the actual content of the resource (for example, a file) and some basic properties (for example, size, see the Length property — however, not all threads support this), as well as the ability to navigate and read. So all that you can pull out of the stream - actually its contents.

If you have FileStream , then the full path to the file, including the name, can be taken from the Name property. Content is best read through StreamReader :

 using (FileStream stream = ...) using (var reader = new StreamReader(stream)) { string content = reader.ReadToEnd(); }