Create Content item in Orchard CMS programmatically with fields

38 Views Asked by At

I have a content type Event define in back office. This content type has a location text field and a date field. I went to create a content item with its two fields.

ContentTypeDefinition contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Event");
var contentItem = _contentManager.New(contentTypeDefinition.Name);

var titlePart = contentItem.As<TitlePart>() ?? new TitlePart();
contentItem.Weld(titlePart);
titlePart.Title = "Title Content Item";

contentItem.Content["location"] = "acccessmeans";

_contentManager.Create(contentItem, VersionOptions.Published);

what can I do?

0

There are 0 best solutions below