Data types using C#

Manually adding a meta type to a page (branch)

The sample code and its key pointers in the following sections demonstrate how to manually add a meta type to a page.

Minimal Example

using (DataConnection connection = new DataConnection(PublicationScope.Unpublished))
  IPage page = connection.Get<IPage>().Last(); // The page in question
  Guid containerId = PageMetaDataFacade.GetAllMetaDataContainers().First().Key;
  Guid myTypeId = typeof(IMyDataType).GetImmutableTypeId();
  Page.AddMetaDataDefinition("MyName", "MyLabel", containerId, myTypeId);
  // Adding default values
  IMyDataType newDataTemplate = DataConnection.New<IMyDataType>();
  newDataTemplate.Name = "Some name";
  // Fill in the rest of the fields
  page.AddNewMetaDataToExistingPages("MyName", newDataTemplate);