【问题标题】:MOSS 2007, programmatically downloading document folder; Can't connect to Document folderMOSS 2007,以编程方式下载文件夹;无法连接到文档文件夹
【发布时间】:2019-12-16 19:16:41
【问题描述】:

我正在尝试以编程方式从 Sharepoint 2007 站点上的文档文件夹中下载所有文件。到目前为止,我能够连接到该站点,但是在连接到文件夹和下载它们时遇到了问题。


try{
    using(SPSite site = new SPSite("http://mysharepointserver/sites/subsite")){
        using(SPWeb web = site.OpenWeb()){
            Console.Write("Connected to site");
            SPFolder testFolder = web.Folder["testFolder"];
            //example method downloading folder
            downloadFolder(testFolder);
        }
    }
}
catch(Exception e){
    Log(e.ToString());
}

我的控制台编写工作正常,所以我知道我正确连接到该站点。 我的日志文件输出:

System.ArgumentException: Value does not fall within the expected range.
   at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)
   at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)

我还尝试打印出以下内容:

using(SPWeb web = site.OpenWeb()){
            Console.Write("Connected to site");
            Console.Write(web.lists);
            SPFolder testFolder = web.Folder["testFolder"];
            //example method downloading folder
            downloadFolder(testFolder);
        }

向控制台输出以下内容:

Connected to site
Microsoft.SharePoint.SPListCollection

但我不确定如何通过 SPListCollection 导航以检索我的文件夹“testFolder”

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: c# .net sharepoint sharepoint-2007


    【解决方案1】:

    当您连接到共享点站点时,有不同类型的库。包含文档和文件夹的库是 DocumentLibrary 而不是 ListLibrary。通过 ID 获得项目/库后,将其转换为正确的 SPDocumentLibrary 以检索所需的项目。

    使用https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spdocumentlibrary?view=sharepoint-server获取DocumentLibrary的不同方法和属性来检索testFolder。

    从 :https://social.msdn.microsoft.com/Forums/en-US/5ee7fb55-5d90-4d28-8990-bf00479f891f/how-to-get-spdocumentlibrary?forum=sharepointdevelopmentprevious 访问文档库项目的示例

    SPSite siteCollection = this.Site;
    SPWeb site = this.Web;
    // obtain query string values
    string ListId = Request.QueryString["ListId"];
    string ItemId = Request.QueryString["ItemId"];
    // create list object and list item object
    SPList list = site.Lists[new Guid(ListId)];
    SPListItem item = list.Items.GetItemById(Convert.ToInt32(ItemId));
    // query for information about list and list item
    string ListTitle = list.Title;
    string ItemTitle = item.Title;
    
    if (list is SPDocumentLibrary) {
      SPDocumentLibrary documentLibrary = (SPDocumentLibrary)list;
      string DocumentTemplateUrl = documentLibrary.DocumentTemplateUrl;
      SPFile file = item.File;
      string FileAuthor = file.Author.Name;
      string FileSize = file.TotalLength.ToString("0,###") + " bits";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 1970-01-01
      • 2018-11-09
      相关资源
      最近更新 更多