1

I'm trying to get an ASP.Net Web Application to be able to write a long filename but keep getting a System.IO.PathTooLongException.

https://learn.microsoft.com/en-us/dotnet/api/system.io.pathtoolongexception?view=netframework-4.8

File.WriteAllText(@"C:\LongFileName" + new string('0', 500) + ".txt", "LongFileName");

I've tried setting group policy and registry settings to enable long file paths. This hasn't worked. I've tried adding an app.manifest file to my project with the following.

<?xml version="1.0" encoding="utf-8"?>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
    </windowsSettings>
</application>

This still isn't working. I'm wondering if the issue is that it being a web application I cannot have a manifest file and this needs to be a setting for IIS Express?

Robin Day
  • 100,552
  • 23
  • 116
  • 167
  • Perhaps this will help: [best-way-to-resolve-file-path-too-long-exception](https://stackoverflow.com/questions/8745215/best-way-to-resolve-file-path-too-long-exception) – Ryan Wilson Nov 09 '21 at 17:05
  • I'm not sure, but in the APIs you need to prefix long file names exceeding MAX_PATH (256) with `\\?\`, have you tried this? See [Maximum Path Length Limitation](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd) – Steeeve Nov 09 '21 at 18:52

0 Answers0