IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
To create a list item you can use the Native API or the Fluent API.
To create a list item using the Native API, you must use the ListsManager class. For more information, see Creating a list item using Native API.
To create a list item using the Fluent API, you must use the list facade. For more information, see Creating a list item using Fluent API.
When creating a list item through the Native API, you must perform the following:
Get the parent list.
First, you must get the parent list for the list item.
For more information about querying lists, see For developers: Query lists.
For more information about finding specific lists, see For developers: Find lists.
Create new list item.
After you get the parent list, you must create new list item.
Set the parent.
To set the parent list for the list item, you use the Parent property of the list item.
Set the required properties.
When creating a new list item, it is recommended to set at least the following properties:
Title
Content
UrlName
DateCreated
You can also set any other properties in this step.
Save the list item.
Save all changes that you have made to the list item.
Publish the list item.
Finally, you publish the list item using the workflow manager.
The following code creates a list item with the specified ID, Parent, Title and Content through the Native API.
NOTE: In the code example below the ID argument is assigned to the master version of the list item.
First, you initialize the ListsManager. You get the parent list using the GetLists method.
You create the list item using the CreateListItem method of the ListsManager class. Note that you can create a list item with either predefined or auto-generated ID depending on which overload of the method you use. The ID argument is assigned to the ID of the master version of the item. Then, you set the parent list and the properties of the list item. It is recommended to set at least the following properties: Title, Content, UrlName and DateCreated. Then, you save the changes. Finally, to publish the list item in live state, you call theMessageWorkflow method of the WorkflowManager class and pass the required parameters.
When creating a list item through the Fluent API, you must perform the following:
Check whether the parent list exists.
First, you must check whether the specified parent list exists.
If it exists, you must get the parent list.
The following code creates a list item with the specified Parent, Title and Content through the Fluent API.
First, you check whether the specified parent list exists using the plural facade of the list. If it exists, you get the list using the singular facade.
Then, you create the list item using the CreateListItem method of the facade. Then, you set the properties of the list item by calling the Domethod of the facade. It is recommended to set at least the following properties: Title, Content, UrlName and DateCreated. Then, you save the changes. To publish the list item in live state, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters. Finally, you return the Id of the list item.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important