How to save files using Microsoft.Win32.SaveFileDialog with filenames longer than MAX_PATH?

200 Views Asked by At

I am trying to save a file:

Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog
        {
            FileName = "verylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexampleverylongexample.foo",
            DefaultExt = ".foo",
            Filter = "Foo Bar|*.foo"
        };

Upon pressing Save in the dialog, I receive this:

The filename, directory name, or volume label syntax is incorrect.

even though I have this in my app.manifest:

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

as mentioned here: https://learn.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation

1

There are 1 best solutions below

0
Mike Makarov On

So yes, what guys mentioned in the comments means that your Windows doesn't support it.

Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions.

Now, to make it cross-Windows, you'd have to create custom file dialog, operating through paths using \\?\Drive:\ style.