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.
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important