views:

589

answers:

3

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)
{
}
+4  A: 

The FileStream's Name property.

Yuriy Faktorovich
Thanks for answering what was apparently an RTFM-type question. I did actually, but it wasn't obvious to me that Name got the path.
A: 

Name.

This was pretty easy to find. In fact, I didn't even have to search - I just typed the URL.

John Saunders
A: 

You can use fs.Name to get the path.

cakeforcerberus