Save content item with text field value set in the code

Topics: Administration, Core, Customizing Orchard, General, Troubleshooting, Writing modules
Jan 3, 2013 at 2:05 PM
Edited Jan 4, 2013 at 1:13 PM

I have my own content part. Then I added three text fields to this part in admin panel. 

I try to create my part item in code and would like to set fields values in code. When debug my code I can see that text fields values are set as I wanted to. But when I open my created content item text fields aren't set as I wanted to.

This is my code snippet:


var part = contentManager.New<MyOwnPart>("MyOwn");
var textFields = part.Fields.Where(x => x.FieldDefinition.Name == "TextField");

((dynamic)textFields.First(x => x.DisplayName == "Dimensions")).Value = "100 x 100";
((dynamic)textFields.First(x => x.DisplayName == "Designer")).Value = "my own designer";
((dynamic)textFields.First(x => x.DisplayName == "Warranty")).Value = "warranty";
Jan 4, 2013 at 12:15 PM
Edited Jan 4, 2013 at 12:15 PM

How to save content item with set text field value in the code?

Jan 7, 2013 at 9:56 AM

Call Create() BEFORE you attempt to assign values to the fields.

Jan 8, 2013 at 7:06 AM
Edited Jan 8, 2013 at 7:06 AM

Oh yeah:) 

It helped me, thank you!