Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Original Path from FileStream

People also ask

How do I view a FileStream file?

C# FileStream read text with StreamReader using FileStream fs = File. OpenRead(fileName); using var sr = new StreamReader(fs); We pass the FileStream to the StreamReader . If we do not explicitly specify the encoding, the default UTF8 is used.

What is the use of FileStream in C#?

The FileStream is a class used for reading and writing files in C#. It is part of the System.IO namespace. To manipulate files using FileStream, you need to create an object of FileStream class. This object has four parameters; the Name of the File, FileMode, FileAccess, and FileShare.

What should you do with a file stream when you are finished with it?

FileStream buffers input and output for better performance. This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try / catch block.


The FileStream's Name property.

See documentation in MSDN


You can use fs.Name to get the path.


Use FileInfo-Class for getting the path.

var fileStream = File.OpenRead(fileName);
var fileInfo = new FileInfo(fileName);

Settings.Default.ThePath = fileInfo.DirectoryName;
Settings.Default.Save();