dm76752
dm76752

Reputation: 113

Windows 10 Maximum Path Length Limitation

I am, like some before me, confused by the Maximum Path Length Limitation. I successfully transferred a tree of files to a NAS using robocopy and a new Windows 10 machine.
On the source machine all files were in 260 characters limit. They were copied with robocopy to the path \nas-3tb-backup\Public\Save_2019 from the path e:. I wanted to check it afterwards with a small C# program but I don't succeed. Both FileInfo and File.OpenRead can't find the file that has an extended path by the NAS name. All programs like Notepad, Visual Studio Code, Windows Explorer have no problems displaying or opening this file. I have tried to use the prefix \\?\ which is shown here: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#maxpath But the attempt with \\?\\\nas-3tb-backup---- failed. There is still a hint in the linked article to extend the path when the registry is changed. I want to avoid this because then I would have to change all Windows computers and since the Windows own programs work without registry hack it should be possible for me.

string fn1 = @"\\?\\\nas-3tb-backup\Public\VeryLongPathToFile";
bool b1 = new FileInfo(fn1).Exists;
if (b1) {
    using (FileStream stream = File.OpenRead(fn1)) {
    var b = stream.ReadByte();
    }
}

Upvotes: 3

Views: 3509

Answers (2)

dm76752
dm76752

Reputation: 113

Solution

Create a Manifest File

The app.manifest file must contain

<application xmlns="urn:schemas-microsoft-com:asm.v3">
  <windowsSettings>
    <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
  </windowsSettings>
</application>

No changes necessary in the config file or computer policy (maybe for Win32 apps but not tested)

Prefix \\?\ don't work for UNC Pathes Local Pathes like c:\ must be written as local UNC Path e.g. \\?\C:\

Test System

Windows 10 Ver. 1909 .Net Framework 4.7 C# .Net Console App 64 Bit

Upvotes: 3

wes
wes

Reputation: 389

Have you changed the app.config file in your C# solution as described here .NET 4.6.2 and long paths on Windows 10.

In this post he created a folder at a very long path but maybe it will help you as well.

The code he used:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>

Upvotes: 3

Related Questions