How to create migration new property contentarea into Page type

Hi! for all

I have a block that displays a couple of input type text. and I need to add a ContentArea
public class OrderConfirmationViewModel
        public string ConfirmationId { get; set; }
        public string Title { get; set; }
        public string MainBody { get; set; }
        public ContentArea AdvertisingContentArea { get; set; }
all code works, the problem is that I have to manually declare the property in

/ episerver / CMS / Admin / and in the tab
"Content type" select "page types" -> "confirmationpage" and manually add my property AdvertisingContentArea 

I understand that this should be solved with a migration but I don't know how to create it.

I don't need to migrate a block not a new model page. I need to migrate a new property.

public class MyNewMigration : IMigration
    public bool Up()
        // Code that will be executed when you click on the “Up” button.
        return true; // If your migration doesn't return "true" the status won't be updated

    public bool Down()
        // Code that will be executed when you click on the “Down” button.
        return true; // If your migration doesn't return "true" the status won't be updated

    public Guid Id => new Guid("598A91B7-0065-4A33-98BD-1473CC4188BA");  // The unique ID of this migration
    public int Order => 1200; // What order the migration should be execute in.
    public string DisplayName => "My new migration"; // What text should be displayed in the migration tool
I don't know if I'm doing it right
public override bool Up()
            var startPage = (StartPage)_contentLoader.Get<StartPage>(ContentReference.StartPage, DefaultLanguage).CreateWritableClone();

            var page = _contentRepository.Get<SessionExpiredPage>(startPage.SessionExpiredPage).CreateWritableClone() as SessionExpiredPage;
            page.PageTypeName = "OrderConfirmationPage";

            //var block = _contentRepository.GetDefault<FreeTextBlock>(page.ContentLink, DefaultLanguage) as IContent;
            //block.Name = @"Cosa 3";

            var contentFragment = ServiceLocator.Current.GetInstance<ContentFragmentFactory>().CreateContentFragment(page.ContentLink, page.ContentGuid, null);

            if (page.MainContentArea == null)
                page.MainContentArea = new ContentArea();

            page.MainContentArea.IsModified = true;

            //_contentRepository.Save(block, SaveAction.Publish);
            _contentRepository.Save(page, SaveAction.Publish);

            return false;

Mar 05, 2021 15:50

programmatically this is how you create a Block in content area property (page.MainContentArea)

          var block = CreateBlockDataInstance("Your-block-type", migrationConfig);
            ((IContent)block).Name = string.IsNullOrEmpty(image.ImageTitle) ? image.Image.ImageLocalURL : image.ImageTitle;
                block.Property["Title"].Value = image.ImageTitle;

                block.Property["Image16x9"].Value = GetImageVaultJsonDataFromIdList("Media", new[] { image.Image.StorageImageId ?? 0 });

            catch (Exception ex)
            _contentRepository.Save((IContent)block, EPiServer.DataAccess.SaveAction.Publish);
            return block;

       BlockData CreateBlockDataInstance(string BlockType, MigrationConfig migrationConfig)

            IContentTypeRepository contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
            ContentType correctType = contentTypeRepository.Load(BlockType);
            return _contentRepository.GetDefault<BlockData>(new ContentReference(migrationConfig.CMSBlockFolder), correctType.ID);
Mar 05, 2021 18:00
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.