I am building an ASP.NET web application that needs to work with long paths. I have it targeting .NET 4.6.2 and everything was perfect since 4.6.2 has long paths turned on by default (Source), until the Windows 10 creators (RS2) update.
Suddenly System.IO was returning max paths exceptions. I did some research and found This post. It seems that post Windows 10 creators (RS2) update, in order for long paths to work it is a requirement to have an app.mainfest with
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
I have verified that adding the app.manifest modification to a console app brings the long path functionality back. The only issue is that this is a web application. I am unable to figure out how to add the equivelant of an app.manifest to a web application.
You could try adding these lines inside your web.config after the <startup>
end tag:
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
Source: .NET 4.6.2 and long paths on Windows 10 (MSDN)
You can try prefixing the file path with \\?\
to specify its a long file path exceeding the MAX_PATH which will be 260 characters. Can find more information in the link below:
https://docs.microsoft.com/en-gb/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
I am unable to figure out how to add the equivalent of an app.manifest to a web application.
Its not exactly standard practice, but you can add a manifest to an ASP .NET Web application. If you are using VS2017, it would look similar to the below screens:
You can try to change this setting using regedit:
run regedit.exe
as administrator
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
[LongPathsEnabled] (DWORD)
to 1
This should solve the problem for ASP.NET also.
The registry key can also be controlled via Group Policy atComputer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With