Below is the code snippet to create a folder in a SharePoint List and adding Items to it.
In the below snippet "lsit" is SPList object in which you are trying to create the folder.
// create a folder under the path specified
web.AllowUnsafeUpdates =True;
folderItem = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
// set the folder name and update
folderItem["Title"] = "My Folder"
folderItem.Update();
//create a listitem object to add item in the foler
SPListItem listItem = list.Items.Add(folderItem.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null);
//Set the values for other fields in the list
listItem["Contact ID"] = <<Contact ID>>;
listItem["Contact Name"] = <<Contact Name>>;
listItem.Update();
web.AllowUnsafeUpdates =False;
web.update();
Hope this helps..
In the below snippet "lsit" is SPList object in which you are trying to create the folder.
// create a folder under the path specified
web.AllowUnsafeUpdates =True;
folderItem = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
// set the folder name and update
folderItem["Title"] = "My Folder"
folderItem.Update();
//create a listitem object to add item in the foler
SPListItem listItem = list.Items.Add(folderItem.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null);
//Set the values for other fields in the list
listItem["Contact ID"] = <<Contact ID>>;
listItem["Contact Name"] = <<Contact Name>>;
listItem.Update();
web.AllowUnsafeUpdates =False;
web.update();
Hope this helps..
No comments:
Post a Comment