MOSS 2007,以编程方式下载文件夹;无法连接到文档文件夹
MOSS 2007, programmatically downloading document folder; Can't connect to Document folder
我正在尝试以编程方式从 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"
如有任何帮助,我们将不胜感激。谢谢!
当您连接到共享点站点时,会出现不同类型的库。包含文档和文件夹的库是 DocumentLibrary 而不是 ListLibrary。通过 ID 获得项目/库后,将其转换为正确的 SPDocumentLibrary 以检索所需的项目。
使用 https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spdocumentlibrary?view=sharepoint-server 获取 DocumentLibrary 的不同方法和属性以检索 testFolder。
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";
}
我正在尝试以编程方式从 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"
如有任何帮助,我们将不胜感激。谢谢!
当您连接到共享点站点时,会出现不同类型的库。包含文档和文件夹的库是 DocumentLibrary 而不是 ListLibrary。通过 ID 获得项目/库后,将其转换为正确的 SPDocumentLibrary 以检索所需的项目。
使用 https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spdocumentlibrary?view=sharepoint-server 获取 DocumentLibrary 的不同方法和属性以检索 testFolder。
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";
}