Get Stream File Location
-
How can I get the location of the file being streamed from the "System.IO.Stream" class?
-
How can I get the location of the file being streamed from the "System.IO.Stream" class?
The Stream class is an abstract base class, and derived classes may not represent a file (for example, MemoryStream represents an in-memory byte stream). In .NET, the FileStream class is usually used to deal with file I/O, so if the stream you're dealing with is based on a file, the Stream will likely be a FileStream instance. You can use FileStream.Name to get the original filename - for example:
string GetStreamFilename(Stream stream)
{
FileStream fs=stream as FileStream;
//if it's a FileStream return its name
if(fs!=null)
return fs.Name;
//otherwise, it's probably not file-based
return null;
}