Great, this makes sense. The end result is that I should see the \App_Data\Sitefinity\Configuration\BlogsConfig.config
modified to include the appropriate XML-block(s) that represent my new dynamic field? Because after running my code against my Sitefinity 4 RC instance I don’t see any noticeable effect. The .config file is not updated nor do I see any changes within the Sitefinity administrative UI.
I added a new dynamic field via the Fluent API as follows (this works, I can see the underlying database table has been modified to include the new column):
f.FieldName = "note";
f.ColumnName = "note";
f.Title = "Note";
f.DBSqlType = "NVARCHAR(MAX)";
f.DBType = "LONGVARCHAR";
Then I ran the following code-block to update the Blogs configuration – This should have added a new Section titled ‘Notes’ with a single field titled ‘Note’:
BlogsConfig blogsConfig = new BlogsConfig();
ContentViewControlElement postsBackEnd = blogsConfig.ContentViewControls["Postsbackend"];
ContentViewDefinitionElement blogsBackendEditPostDefinition = postsBackEnd.ViewsConfig["BlogsBackendEditPost"];
DetailFormViewElement detailView = (DetailFormViewElement)blogsBackendEditPostDefinition;
ContentViewSectionElement noteSection = new ContentViewSectionElement(detailView.Sections);
TextFieldDefinitionElement noteField = new TextFieldDefinitionElement(noteSection.Fields)
ID = "noteFieldControl",
DataFieldName = "note",
DisplayMode = FieldDisplayMode.Write,
Title = "Note",
CssClass = "sfTitleField",
WrapperTag = HtmlTextWriterTag.Li,
ResourceClassId = typeof(BlogResources).Name,
But in the end the code runs successfully and nothing is performed (neither the Section nor the Field are created).
Am I doing something incorrect? Do I need to run some instance method to have the changes persist themselves?