CMS7 programmatically create dynamic property
Haven’t used dynamic properties in a long while, but yesterday when building an external module I thought that a dynamic content reference property would be perfect for my needs.
But I wanted to create it programmatically so the deployment would only be copying of files.
I only found a blog post for CMS6. Lucky for me it wasn’t to much that differed. CMS7 code below:
private void SetupDynamicProperty(){var TabDefinitionRepository = ServiceLocator.Current.GetInstance<ITabDefinitionRepository>();var PropertyDefinitionTypeRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionTypeRepository>();var PropertyDefinitionRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();try{PropertyDefinition pd = new PropertyDefinition();pd.ContentTypeID = 0; // 0 == Dynamic propertypd.Name = "YourPropertyName;pd.EditCaption = "HandbookStartPage";pd.Type = PropertyDefinitionTypeRepository.Load(4); // 4 == PageReferencepropertyDefinitionRepository.Save(pd);}catch { }}
Comments