【问题标题】:How to save files using Microsoft.Win32.SaveFileDialog with filenames longer than MAX_PATH?如何使用 Microsoft.Win32.SaveFileDialog 保存文件名超过 MAX_PATH 的文件?
【发布时间】:2019-07-25 23:11:53
【问题描述】:

我正在尝试保存文件:

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

在对话框中按保存后,我会收到以下信息:

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

即使我的 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>

这里提到:https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation

【问题讨论】:

  • 您使用的是哪个操作系统?
  • 我相信@dymanoid 询问的是哪个版本的 Windows。
  • Windows 10 版本 1803 内部版本 17134.471
  • 您是否尝试过该参考中的注册表破解(仅出于完整性考虑)?
  • 我可以在 1809 Windows 10 桌面上使用 WIN32 API CreateFile2 重现此问题,我将通过反馈中心报告此问题。

标签: c# wpf windows winapi max-path


【解决方案1】:

所以是的,cmets 中提到的那些人意味着你的 Windows 不支持它。

从 Windows 10 开始,版本 1607,MAX_PATH 限制已从常见的 Win32 文件和目录函数中删除。

现在,要使其跨 Windows,您必须创建自定义文件对话框,通过使用 \\?\Drive:\ 样式的路径进行操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    相关资源
    最近更新 更多