我在SharePoint 2010列表中有大約20K項目,我希望以編程方式安排每個5k項目在文件夾中,並且確保新添加的項目也在文件夾中達到5k的限制。以編程方式將Sharepoint列表的現有項目添加到文件夾
我還沒有在編程方式上在SharePoint中創建文件夾。有人可以幫我一段代碼。
我在SharePoint 2010列表中有大約20K項目,我希望以編程方式安排每個5k項目在文件夾中,並且確保新添加的項目也在文件夾中達到5k的限制。以編程方式將Sharepoint列表的現有項目添加到文件夾
我還沒有在編程方式上在SharePoint中創建文件夾。有人可以幫我一段代碼。
對於在SPList中創建文件夾,使用下面的示例代碼它會幫助你。
SPSite oSite = new SPSite("http://localhost/");
SPWeb oWeb = oSite.OpenWeb();
//Provide SPList name which you use...
SPList oList = oWeb.Lists["testlist"];
oWeb.AllowUnsafeUpdates = true;
//Add a Folder as List Item in SPList as below
SPListItem folderItem = oList.Items.Add(oList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
//Add Folder Title here
folderItem["Title"] = "1-5000-Items-Folder";
folderItem.Update();
oWeb.AllowUnsafeUpdates = false;
對於在SPList中創建文件夾使用下面的示例代碼,它會幫助你。
SPSite oSite = new SPSite("http://localhost/");
SPWeb oWeb = oSite.OpenWeb();
//Provide SPList name which you use...
SPList oList = oWeb.Lists["testlist"];
oWeb.AllowUnsafeUpdates = true;
//Add a Folder as List Item in SPList as below
SPListItem folderItem = oList.Items.Add(oList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
//Add Folder Title here folderItem["Title"] = "1-5000-Items-Folder";
folderItem.Update();
oWeb.AllowUnsafeUpdates = false;
請使用CAML查詢來循環SP中的文件夾。也絕對不要使用list.Items.Add()而是使用listitems.add()。 http://stackoverflow.com/faq#signatures -
SPQuery query = new SPQuery();
query.Query = "<Where><And><Eq><FieldRef Name='LinkTitle'/><Value Type='Text'>" +folderName + "</Value></Eq><Eq><FieldRef Name='FSObjType'/><Value Type='Lookup'>1</Value></Eq></And></Where>";query.ViewAttributes = "Scope=\"RecursiveAll\"";
SPListItemCollection items = list.GetItems(query);
if (items.Count == 0){Create a folder}
else{
SPListItem listItem = list.AddItem(folderItem.Folder.ServerRelativeUrl,SPFileSystemObjectType.File, null);}
請不要在計算器上使用的簽名:
同時找到一個文件夾使用的代碼 – Ryan