SaveFileDialog does not handle longpath format RRS feed

  • Question

  • Targeting core 3.1 on windows 10

    Setting a Microsoft.Win32.SaveFileDialog.InitialDirectory = "\\?\C:\" results in the error:

    System.ArgumentException: Value does not fall within the expected range.
      at at MS.Internal.Interop.HRESULT.ThrowIfFailed()
      at at MS.Internal.AppModel.ShellUtil.GetShellItemForPath(String path)
      at at Microsoft.Win32.FileDialog.PrepareVistaDialog(IFileDialog dialog)
      at at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner)
      at at Microsoft.Win32.FileDialog.RunDialog(IntPtr hwndOwner)
      at at Microsoft.Win32.CommonDialog.ShowDialog()

    This is a legitimate path according to the documentation https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#short-vs-long-names

    Pasting it in explorer works, Directory.Exists("\\?\C:\") returns true.

    saveFileDialog.CheckPathExists returns false after this is set.

    I understand if this is a compatibility issue and it cant work because this is a win32 library, but as far as I understand there is no new version of SaveFileDialog that can be substituted to work around this in WPF.

    Is there some trick I can use to deal with this? I could manually parse the path and remove the \\?\ prefix but then if the path really is long it would (probably?) still crash.

    EDIT: https://docs.microsoft.com/en-us/answers/questions/159442/savefiledialog-does-not-handle-longpath-format.html

    Wednesday, August 5, 2020 12:46 PM

All replies

  • Hi Duncan1248

    Thank you for posting here.

    Since your question is more related to WPF, so I suggest you post your question in WPF forum for more efficient responses.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 6, 2020 5:50 AM