Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • slseverance1 2 posts 22 karma points
    Sep 17, 2023 @ 04:57
    slseverance1
    0

    v10 c# create content type

    Trying to create a ContentType with a class in a package. Does anyone know how this should be done?

        using Umbraco.Cms.Core.Models; 
        using Umbraco.Cms.Core.Services; 
    
        namespace MyProject
        {
            public class ContentTypeCreator
            {
                private readonly IContentTypeService _contentTypeService;
    
            public ContentTypeCreator(IContentTypeService contentTypeService)
            {
                _contentTypeService = contentTypeService;
            }
    
            public void CreateContentType()
            {
                var ct = new ContentType(-1)
                {
                    Alias = "MyContentType",
                    Name = "My Content Type",
                    Description = "This is my custom content type",
                    Icon = "icon-document"
                };
    
                _contentTypeService.Save(ct);
            }
        }
    }
    
  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Sep 17, 2023 @ 06:59
  • slseverance1 2 posts 22 karma points
    Sep 17, 2023 @ 16:08
    slseverance1
    0

    Thank you for this!

Please Sign in or register to post replies

Write your reply to:

Draft