I am trying to get security information of some files and directories inside a network folder. Unfortunately some files and directories path exceed their character limits 260/248 respectively. I found so many information to use Win32 P/Invoke, use .NET Framework 4.6.2 etc. I was able to use a code by Kim Hamilton to iterate through each files and directories inside whose path exceeds the length limit but I could not use it to get the security information.
Below is my simple C# code containing a path which is above 260 characters. It will throw a Path Too Long Exception. Could you please help me solve it in this scenario.
using System.IO;
using System.Security.AccessControl;
namespace Microsoft.Experimental.IO
{
class Program
{
public static void Main(string[] args)
{
string path = @"\\Domain\UserData\VeryLongPath"; //This is above 260 characters
DirectoryInfo info = new DirectoryInfo(path);
DirectorySecurity security = Directory.GetAccessControl(path);
}
}
}