Monday 22 January 2018

Long UNC paths

Zeta Long Paths


I just did a quick check of both regarding longpath-support and ACL managment functions:
FileSecurity fileSecurity = File.GetAccessControl(fileName);

foreach (FileSystemAccessRule ar in fileSecurity.GetAccessRules(true, true, typeof(NTAccount)))
{
    string account = ar.IdentityReference.Value;

    Console.WriteLine(account);
}
with using System.IO you get the normal behavior (exception with long paths)
If you switch to one of the above libraries:
using Alphaleonis.Win32.Filesystem;
or
using Pri.LongPath;
the above code snippets compiles and runs without exception even if the filename exceeds 259 characters.
I have no real experience with both libaries, but AlphaFS seems more complete and supports UNC paths (\\server\share\dir1\file1.txt)
In addition, AlphaFS is licensed under MIT (which is compatible with GPL, so it can be used in either commercial, but also GPL licensed projects).
LongPath is licensed under LGPL.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.