【问题标题】:Microsoft Office Document shows Sharepoint URL instead of LocalMicrosoft Office 文档显示 Sharepoint URL 而不是本地
【发布时间】:2015-02-05 19:59:10
【问题描述】:

情况:OneDrive for Business 将文件从 Sharepoint 站点文档库同步到本地目录:

C:\Users\users\Sharepoint\Library\Test.pttx

但是使用 PowerPoint InterOp:

presentation.Path

是:

https://company.sharepoint.com/Library/Shared%20Documents/

Sharepoint 的正确路径是什么。

如何访问本地目录?

更新:我在 MSDN 上找到了 similar question,但没有答案

【问题讨论】:

    标签: c# sharepoint office-interop onedrive


    【解决方案1】:

    如果我理解正确,您想在 Powerpoint (VSTO) 中获取同步目录的本地路径吗? Powerpoint 对象模型中的方法,例如 presentation.GetLocalPath()

    我不知道为什么(在您的问题中的MSDN link)MSFT CSG 工程师说这是不可能的。

    抱歉错误,经过进一步调查,是 不可能。对于 Word 应用程序,文件存储在 OneDrive,“离线”是 OneDrive 的缓存模式,它是 对 Word 应用程序透明(Word 应用程序只知道它是一个 OneDrive 上的文档),因此当您检查打开的位置时 文件,位置是“http://d.docs.live.net/xxxx/xx.docx”而不是 比“C:\XXX\XXX”。

    本文向您展示如何Change the location where you sync SharePoint libraries on your computer。显然,Powerpoint 互操作库中没有方法,但它绝对是可能的。

    1) 我的第一个想法是查看 OneDrive for Business 同步应用程序向导是否保存任何注册表项或类似内容(使用 ProcessMonitor),但它可能将本地目录存储在云中。

    2) 我的第二个想法有点跳出框框,只需在https://company.sharepoint.com/Library/Shared%20Documents/LocalDrivePath.txt 中放入一个文本文件,然后创建一个名为presentation.GetLocalPath() 的扩展方法并使用WebClient 类下载字符串。

    伪代码:

    public string GetLocalPath(this Microsoft.Office.Interop.PowerPoint.Presentation presentation)
    {
        WebClient client = new WebClient();
        string localPath = client.DownloadString(presentation.Path + "LocalDrivePath.txt");
    
        //Some good old protective programming to quickly identify the problem if the file doesn't exist
        if (!string.IsNullOrEmpty(localPath)) throw new Exception("Issue: LocalDrivePath.txt not found in " + presentation.Path + Environment.Newline + "Please add the file for this Office Documents' sync'd (offline) local folder to be identified.");
    
        return localPath;
    }
    

    这样称呼它:

    presentation.GetLocalPath();
    

    【讨论】:

    • 非常感谢您对此进行调查。对于 1) 所以没有写入注册表项,我们不知道它存储路径的位置对吗?对于 2) 我是否正确理解我必须至少知道一次位置才能将其存储在 .text 中?我的意思是,如果我知道位置,那么我可以将它存储在任何地方,不是吗?我的另一个想法是在本地搜索文件和路径的路径部分。
    • 如果文件夹应该使用方法 2 更改,那么第三种方法(搜索文件)似乎是一个不错的选择。当你找到可以将其存储在任何地方的目录时,你是对的,一个 txt 文件在 SharePoint 中是最容易演示的。
    【解决方案2】:

    根据这个post,可以在这个多字符串注册表值中查找同步的文件夹:

    HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Common \Internet\LocalSyncClientDiskLocation

    鉴于您的本地路径和 SharePoint URL 看起来像

    C:\Users\User\SharePoint\Library - Documents\Folder\SubFolder\Document.pptxhttps://***.sharepoint.com/Library/Shared%20Documents/Folder/SubFolder/Document.pptx,

    您可以尝试从 URL 中提取本地部分 Folder/SubFolder/Document.pptx,将其添加到从注册表值检索到的本地文件夹路径中并检查文件是否存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 2013-09-29
      • 2018-11-27
      • 1970-01-01
      相关资源
      最近更新 更多