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 1932 posts 6722 karma points MVP 3x c-trib
    Sep 17, 2023 @ 06:59
  • slseverance1 2 posts 22 karma points
    Sep 17, 2023 @ 16:08
    slseverance1
    0

    Thank you for this!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies