Last active
October 18, 2024 15:33
SF_10.1, SF_10.2, SF_11.0, SF_11.1, SF_11.2, SF_12.0, SF_12.1, SF_12.2, SF_13.0, SF_13.1, SF_13.2, SF_13.3, SF_14.0, SF_14.1, SF_14.2, SF_14.3 - https://docs.sitefinity.com/for-developers-create-list-items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text.RegularExpressions; | |
using Telerik.Sitefinity.Lists.Model; | |
using Telerik.Sitefinity.Workflow; | |
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Lists | |
{ | |
public partial class ListsSnippets | |
{ | |
public static Guid CreateListItemFluentAPI(Guid parentListId, string title, string content) | |
{ | |
int count = 0; | |
Guid id = Guid.Empty; | |
// Check whether the parent list exists | |
App.WorkWith().Lists().Where(l => l.Id == parentListId).Count(out count); | |
if (count > 0) | |
{ | |
// Get the parent and create the list item | |
App.WorkWith().List(parentListId).CreateListItem().Do(listItem => | |
{ | |
// Get the Id of the list item | |
id = listItem.Id; | |
// Set the list item properties | |
listItem.Title = title; | |
listItem.Content = content; | |
listItem.Urls.Clear(); | |
listItem.UrlName = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); | |
listItem.DateCreated = DateTime.Now; | |
}).Publish().SaveChanges(); | |
} | |
return id; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment