首页 > 解决方案 > 查找超过 SharePoint 400 个字符限制的路径

问题描述

我们最近迁移到在线 SharePoint 并发现我们的一些路径正在获取损坏的文件,因为它们超过了 SharePoint 设置的 400 个字符的限制。我只是我们特定站点的管理员,而不是我们 SharePoint 租户的全局管理员,因此尝试使用 SharePoint 的 PowerShell 集成不起作用。我还尝试在资源管理器视图中查看并从那里运行 PowerShell 以查找任何内容 -gt 400,但存在 Windows 限制,即在出现错误之前只能找到最多 248 个字符的路径。有没有人遇到过这个问题或知道任何解决方法?

我曾尝试将模块SharePointPnPPowerShellOnline与 PowerShell 一起使用,但由于我不是全局管理员而出现禁止错误。我还尝试在 Windows 资源管理器视图中递归查看,但出现错误。

这是尝试在 Windows 资源管理器视图中执行此操作时出现的错误:

Get-ChildItem :指定的路径、文件名或两者都太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符

标签: powershellsharepoint

解决方案


您是否考虑过使用 SharePoint 在线 CSOM?你可以使用这个 nuget -> SharePointPnP

有了这个,您可以实现任何类型的应用程序(如控制台应用程序)并获取所有文件夹中的所有文件夹、文件和文件,并获取它们的名称、路径或所需的任何内容,并检查它是否超过 400 个字符。(请记住,像 FileServerRelativeUrl 这样的附加列需要在上下文中加载)

try
{
    string siteUrl = "SiteURL";
    AuthenticationManager authManager = new AuthenticationManager();
    using (ClientContext context = authManager.GetWebLoginClientContext(siteUrl))
    {
        List list = context.Web.Lists.GetByTitle("LibName");
        context.Load(list);
        context.Load(list.RootFolder);
        context.Load(list.RootFolder.Folders);
        context.Load(list.RootFolder.Files);
        context.ExecuteQuery();
        FolderCollection folderCol = list.RootFolder.Folders;
        foreach (Folder f in folderCol)
        {
            context.Load(f.Files);
            context.ExecuteQuery();
            FileCollection innerFileCol = f.Files;
            foreach (File file in innerFileCol)
            {
                //var x = file.Name;
                // ToDo other logic here 
            }
        }
        FileCollection fileCol = list.RootFolder.Files;
        foreach (File file in fileCol)
        {
            //var x = file.Name;
            // ToDo other logic here 
        }
    }
}
catch (Exception ex)
{
    // log error
    throw;
}

我希望它会有所帮助:)


推荐阅读