我创建了一个应用程序,下载SP站点中的所有文档库,但有一次它给了我这个错误(我试着看谷歌但无法找到任何东西,现在如果有人知道解决这个问题的任何技巧,请回复否则谢谢看着它)
System.IO.PathTooLongException:指定的路径,文件名或两者都太长.完全限定的文件名必须少于260个字符,目录名必须少于248个字符.在System.IO.Path.NormalizePathFast(字符串路径,布尔fullCheck)在System.IO.Path.GetFullPathInternal(字符串路径)在System.IO.FileStream.Init(字符串路径,的FileMode模式,FileAccess的访问,权限的Int32,布尔useRights ,文件共享份额,缓冲区大小的Int32,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,字符串MSGPATH,布尔bFromProxy)在System.IO.FileStream..ctor(在系统字符串路径,的FileMode模式,FileAccess的访问,文件共享份额,缓冲区大小的Int32,FileOptions选项). IO.File.Create(String path)
它达到字符串的限制,代码如下,
#region Downloading Schemes
private void btnDownload_Click(object sender, EventArgs e)
{
TreeNode currentNode = tvWebs.SelectedNode;
SPObjectData objectData = (SPObjectData)currentNode.Tag;
try
{
CreateLoggingFile();
using (SPWeb TopLevelWeb = objectData.Web)
{
if(TopLevelWeb != null)
dwnEachWeb(TopLevelWeb, TopLevelWeb.Title, tbDirectory.Text);
}
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("Exception caught when tried to pass TopLevelWeb:{1}, Title = {2}, object data to (dwnEachWeb_method), Exception: {0}", ex.ToString(), objectData.Web, objectData.Title));
}
finally
{
CloseLoggingFile();
}
}
private void dwnEachWeb(SPWeb TopLevelWeb, string FolderName, string CurrentDirectory)
{ …Run Code Online (Sandbox Code Playgroud) 当我递归一些文件夹和文件时,我遇到这个错误:
指定的路径,文件名或两者都太长.完全限定的文件名必须少于260个字符,目录名必须少于248个字符.
这是我的功能
private void ProcessDirectory(DirectoryInfo di)
{
try
{
DirectoryInfo[] diArr = di.GetDirectories();
foreach (DirectoryInfo directoryInfo in diArr)
{
if (StopCheck)
return;
ProcessDirectory(directoryInfo);
}
ProcessFile(di);
}
catch (Exception e)
{
listBoxError.Items.Add(e.Message);
}
TextBoxCurrentFolder.Text = di.ToString();
}
Run Code Online (Sandbox Code Playgroud)
我不能让目录名更短,因为我不允许这样......我怎么能解决这个问题呢?
补充: 这是另一个功能:
private void ProcessFile(DirectoryInfo di)
{
try
{
FileInfo[] fileInfo = di.GetFiles();
if (fileInfo.LongLength != 0)
{
foreach (FileInfo info in fileInfo)
{
Size += info.Length;
CountFile++;
}
}
}
catch (Exception e)
{
listBoxError.Items.Add(e.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
EDIT 在他使用Zeta Long Paths的地方找到了这个: …