Getting Original Path from FileStream

user116592 picture user116592 · Jul 22, 2009 · Viewed 41.4k times · Source

Given a System.IO.FileStream object, how can I get the original path to the file it's providing access to?

For example, in the MyStreamHandler() function below, I want to get back the path of the file that created the FileStream:

public static void Main() 
{
    string path = @"c:\temp\MyTest.txt";
    FileStream fs = File.Create(path));

    MyStreamHandler(fs);
    MyOtherStreamHandler(fs);

    fs.Close();
    fs.Dispose();
}

private static void MyStreamHandler(FileStream fs)
{
    // Get the originating path of 'fs'
} 

private static void MyOtherStreamHandler(FileStream fs)
{
}

Answer

Yuriy Faktorovich picture Yuriy Faktorovich · Jul 22, 2009

The FileStream's Name property.

See documentation in MSDN