2011-10-20 74 views

回答

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

請不要在計算器上使用的簽名:

同時找到一個文件夾使用的代碼 – Ryan

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; 
0

請使用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);} 
相關問題