Reputation: 4279
I need to get the path of the original file in the stream.
I read that I need to use the "Name" property of the FileStream to get it's path.
So far so good.
The problem is I have a regular System.IO.Stream and not FileStream, and therefore I don't have the "Name" property.
I read that there is a Stream.CopyTo method: http://msdn.microsoft.com/en-us/library/dd782932.aspx
I planned to convert my Stream to FileStream like that:
System.IO.FileStream fileStream = new System.IO.FileStream(?????);
using (stream)
{
stream.CopyTo(fileStream);
}
But FileStream has no parameterless constructor.
How can I solve it?
Upvotes: 0
Views: 5108
Reputation: 5685
Assuming the Stream is an instance of a FileStream you can cast the Stream down to a FileStream:
var fileStream = stream as FileStream;
The only way you'll be able to get the path name from the Stream instance is if you are able to cast it down to a class that provides a way of accessing the path.
Upvotes: 2
Reputation: 3109
getting path of stream
System.IO.FileStream Stream = ....;
FileStream fs = stream as FileStream;
if (fs != null)
{
// now you can check its path
}
else
{
// you cant check its path
}
Upvotes: 1