Say you get a file handle from some outside DLL and instantiate a FileStream
with it. It works just fine for reading and writing.
Then you want the path and name of that handle and try to access the Name property of your FileStream object, and it returns 'unknown'.
This is true for the constructors which takes file handles:
public FileStream(IntPtr handle, ...
public FileStream(SafeFileHandle handle, ...
I know the short answer, because it's not implemented. The private field _fileName
of FileStream
is never assigned in those constructors.
Seems the API to get the name from a handle involves more than one line of code, but I still think they could have bothered to include this.
So the real questions is: Why haven't they? Or did they just forget?