c# - 如何使用 Microsoft.Win32.SaveFileDialog 保存文件名超过 MAX_PATH 的文件?
问题描述
我正在尝试保存文件:
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>
解决方案
所以是的,评论中提到的那些人意味着你的 Windows 不支持它。
从 Windows 10版本 1607开始,MAX_PATH 限制已从常见的 Win32 文件和目录函数中删除。
现在,要使其跨 Windows,您必须创建自定义文件对话框,通过使用\\?\Drive:\
样式的路径进行操作。
推荐阅读
- spring - Spring Batch - 自定义 FileItemWriter 的零星问题
- python - mpl_finance 删除 Candlestick Python 上的空日期
- r - 将 Googleway 输出转换为数据框时出错
- c# - 从 PNG 文件的 URI 创建具有透明度的位图对象
- php - C++ PHP 桌面和 CEF 崩溃 LoadUrl()
- java - 如何获取数据或识别标签,即使用 Selenium Java 成功完成
- docker - Dockerhub repo 图像解析不起作用
- mongodb - 获取 mongo db 数组中特定元素的值
- mysql - 为什么count(*)即使有结果也返回0?
- php - 限时购车 Laravel