以编程方式将Sharepoint列表的现有项添加到文件夹

时间:2011-10-20 16:25:01

标签: sharepoint sharepoint-2010

我在sharepoint 2010列表中有大约20K项目,我想以编程方式安排文件夹中的每个5k项目,并确保新添加的项目在达到5k限制时也在文件夹中。

我还没有以编程方式在sharepoint中创建文件夹。有人可以用一段代码帮助我。

3 个答案:

答案 0 :(得分:0)

对于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;

答案 1 :(得分:0)

对于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; 

答案 2 :(得分:0)

请使用CAML查询循环SP中的文件夹。也绝不使用list.Items.Add()而是使用listitems.add()。

查找文件夹时使用代码:

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);}