How come the Name property is <Unknown> on a FileStream which uses handle constructors?

Posted by Mikael Svenson on Stack Overflow See other posts from Stack Overflow or by Mikael Svenson
Published on 2010-04-10T15:52:06Z Indexed on 2010/04/10 15:53 UTC
Read the original article Hit count: 330

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about filestream