I have a custom list which can contain a CustomContentType. This is how i create a new item:
//Create root folder
SPListItem rootItem = navigation.Items.Add();
SPContentType folderType = navigation.ContentTypes["ListLevel"];
rootItem[SPBuiltInFieldId.Title] = "root";
rootItem["ContentTypeId"] = folderType.Id;
rootItem.Update();
The problem is, when I'm looking at my list after this I see that:
When I go to the list via a webbrowser and create the content type manually, everthing is fine. (Which means that the Title is "root" and not the ID).
Thank you both for you answers!
The solution was a mixture of both answers. Additionally you have to reload the list:
//Create root folder
SPListItem rootItem = navigation.Items.Add();
SPContentType contentType = navigation.ContentTypes["ListLevel"];
rootItem["ContentTypeId"] = contentType.Id;
rootItem["Title"] = "root";
rootItem.Update();
navigation.Update();
rootItem = navigation.GetItemById(rootItem.ID);
rootItem["Name"] = "root";
rootItem.Update();
The "name" field corresponds to the filename. Despite what you see in the column heading, the 1125_.000 is the filename of the list item, which is automatically generated if you don't supply one:
rootItem["Name"] = "myname";
"Name" is a built-in field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With