SharePoint Blog

How to programmatically Create SPListItem in a SPFolder

Leave a comment

Sample Code to Create SPListItem in a SPFolder

SPSite mySite = new SPSite(http://ServerName/sitename);
SPWeb web = mySite.OpenWeb();
SPList list = web.Lists[“ListName”];
SPFolder f = web.GetFolder(http://ServerName/sitename/Lists/ListName/FolderName);
SPListItemCollection itemColl = list.Items;
SPListItem item = itemColl.Add(f.ServerRelativeUrl , SPFileSystemObjectType.File, null);
item[“Title”] = “Added from Code”;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s