gpt4 book ai didi

c# - 如何在长名称的文件夹中创建文件。 (避免 PathTooLongException)

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:20 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to avoid System.IO.PathTooLongException?

在我的应用程序文件夹结构中有很长时间。我需要保存在此文件夹中的文件(我无法更改模式文件夹!)

[已编辑]

using (var fileStream = File.Create(@"\\?\" + filePath, (int) file.Value.Length))
{
var bytesInStream = new byte[file.Value.Length];
file.Value.Read(bytesInStream, 0, bytesInStream.Length);
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
}

问题是完整路径“filePath”超过了260个字符!

错误:

System.IO.PathTooLongException The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

但是他必须保存在这个文件夹里!

如何在不改变文件夹结构或文件名的情况下,将这个文件保存到这个文件夹中?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com