我在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