alphaleonis / AlphaFS

AlphaFS is a .NET library providing more complete Win32 file system functionality to the .NET platform than the standard System.IO classes.
http://alphafs.alphaleonis.com/
MIT License
562 stars 99 forks source link

Different behavior between System.IO.File.Open / Alphaleonis.Win32.Filesystem.File.Open #438

Closed Ash014 closed 6 years ago

Ash014 commented 6 years ago

I'm trying to use AlphaFS in order to replace System.IO in my application.

I have a different behavior when I use System.IO.File.Open() and Alphaleonis.Win32.Filesystem.File.Open(). The variable "Name" of FileStream object indicates "Unknow" with Alphaleonis.Win32.Filesystem lib while the System.IO lib indicates the full path of my file.

FileStream fs = Alphaleonis.Win32.Filesystem.File.Open(filepath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);

fs.Name => "Unknow"

FileStream fs = System.IO.File.Open(filepath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);

fs.Name => "C:/....."

Do you have an idea to solve that?

Yomodo commented 6 years ago

It seems that the text: "[Unknown]" is inside .NET: IO_UnknownFileName = [Unknown]

Unfortunately, I failed to figure out why this value is returned.

Yomodo commented 6 years ago

It seems you can use this to still get the full path:

using (var fs = Alphaleonis.Win32.Filesystem.File.Open(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
    var path = Alphaleonis.Win32.Filesystem.Path.GetRegularPath(Alphaleonis.Win32.Filesystem.Path.GetFinalPathNameByHandle(fs.SafeFileHandle));

    Console.WriteLine(path);
}