This is not document library, righ?
If not this will do (not the best code I wrote but it works):
string folderName = "MyFolderName";
using (SPSite site = new SPSite("http://mycoolsite/"))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyList"];
string rootUrl = list.RootFolder.Url;
SPListItem item = list.Items.Add();
item["ContentType"] = "Folder";
item.Update();
SPFolder folder = web.GetFolder(string.Format("{0}/{1}", list.RootFolder.Url, item.DisplayName));
folder.MoveTo(string.Format("{0}/{1}", list.RootFolder.Url, folderName));
}
}
As far as I know SPFolder.MoveTo() is only option for folder renaming .
Or simply use this Create Sub Folders in Lists Programmatically
string folderName = "MyFolderName";
using (SPSite site = new SPSite("http://mycoolsite/"))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyList"];
SPListItem item = list.AddItem("", SPFileSystemObjectType.Folder, folderName);
item.Update();
}
}
And little explanation: First example is what question owner wants: Create item with Content type Folder and set/change its name. Second one is just adding folder to SPList.