This post is written by guest Fahad Ahmed
This article is about creating a folder in SharePoint 2010 and then adding items in that folder programmatically using Visual Studio 2010. First of all from the List setting in SharePoint 2010, you have to allow the list to create New Folders in it. To do this, go to List Settings than advance Settings and then allow the creation of “New Folder”.
Once done with the setting, in your Visual Studio 2010 Type in the following Code to create the folder. To create folder, first open the site and then list by passing the valid URL.
SPSite sitec = new SPSite("http://Servername/Lists");
SPWeb webc = sitec.OpenWeb();
string listUrlc = "/Lists/Tasks";
SPList listc = webc.GetList(listUrlc);
SPListItem newfolder = listc.Items.Add("Http://Servername/lists/tasks",
SPFileSystemObjectType.Folder);
newfolder["Title"] = “Task Folder”;
newfolder.Update();
Once the Folder is created, now address to this folder and add items.
string listUrl = "/Lists/Tasks/;
SPList list = web.GetList(listUrl);
SPListItem createitem = list.Items.Add("http://Servername/lists/tasks/" +
“Task Folder”, SPFileSystemObjectType.File, null);
list.Fields["Item Child Count"].ReadOnlyField = false;
list.Fields["Item Child Count"].Update();
createitem["Title"] = “New Item”;
Output

The above section will create item in the selected folder.