Copied to clipboard

Flag this post as spam?

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


  • MuirisOG 382 posts 1284 karma points
    Sep 29, 2016 @ 15:43
    MuirisOG
    0

    "Child items" tab appears with my Media type when created programmatically

    I've created a custom Media Type (for Images) in code, and have uploaded images into the new Media Type.

    However, it has created a "Child Items" tab for each one of the images I uploaded into my custom media type, visible when I click an image in the Media section.

    This isn't visible when I inspect the Media Type in the Settings section.

    I haven't specified permissions so I'm not sure why it has a "Child items" tab.

    Any help would be great.

    Thanks,

    Muiris

  • Sven Geusens 169 posts 881 karma points c-trib
    Sep 30, 2016 @ 14:37
    Sven Geusens
    0

    Could you post the code that is generating these media items?

  • MuirisOG 382 posts 1284 karma points
    Sep 30, 2016 @ 15:07
    MuirisOG
    0

    Hi Sven here's my code (in VB.NET - comments are prefixed with a single quote).

    Private Sub createMediaType(sender As Object, e As System.EventArgs) Handles btnCreateMediaType.Click
        'This will help with getting the byte stream
        'https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53736-How-to-upload-images-programmatically-into-a-upload-property-in-umbraco-7-back-office-content-page
        'https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/59411-Creating-and-Saving-Media-Programmatically
        'https://our.umbraco.org/forum/developers/api-questions/47792-Create-Media-Programmatically-in-V7
        Dim userService = ApplicationContext.Current.Services.UserService
    
        Dim cts As IContentTypeService = ApplicationContext.Current.Services.ContentTypeService
        Dim cs As IContentService = ApplicationContext.Current.Services.ContentService
        'Dim fs As IFileService = ApplicationContext.Current.Services.FileService
        Dim dts As IDataTypeService = ApplicationContext.Current.Services.DataTypeService
        Dim ms As IMediaService = ApplicationContext.Current.Services.MediaService
    
        'create a new images folder in the Media Section
        'This will be where the imported images will sit
        Dim folderType As MediaType = cts.GetMediaType("Folder")
        Dim med As New Media("webImages", -1, folderType)
        med.CreatorId = 0
        ms.Save(med)
    
        'new MediaType
        Dim mediatype As New MediaType(-1)
        'set some initial properties
        mediatype.Alias = "webImage"
        mediatype.Name = "web Image"
        mediatype.Description = "This Image Type will hold web images with description fields for Welsh"
        mediatype.Icon = "icon-picture"
        'create an image MediaType 
        Dim imageType As MediaType = cts.GetMediaType("Image")
        mediatype.AddContentType(imageType)
        mediatype.CreatorId = 0
    
        ''this helps to create a data type field in the media type
        Dim txtDataTypeDef As DataTypeDefinition = dts.GetDataTypeDefinitionById(-88)
    
        'create a tab for this media type to hold property values
        'English tab and properties
        mediatype.AddPropertyGroup("English")
    
        'title
        Dim txtPropType02 = New Umbraco.Core.Models.PropertyType(txtDataTypeDef)
        txtPropType02.Name = "Title"
        txtPropType02.Alias = "en_gb_title"
        mediatype.AddPropertyType(txtPropType02, "English")
        'keywords
        Dim txtPropType01 = New Umbraco.Core.Models.PropertyType(txtDataTypeDef)
        txtPropType01.Name = "Keywords"
        txtPropType01.Alias = "en_gb_keywords"
        mediatype.AddPropertyType(txtPropType01, "English")
        'description
        Dim txtPropType03 = New Umbraco.Core.Models.PropertyType(txtDataTypeDef)
        txtPropType03.Name = "Description"
        txtPropType03.Alias = "en_gb_description"
        mediatype.AddPropertyType(txtPropType03, "English")
    
        'create a tab for this media type to hold property values
        'Welsh tab and properties
        mediatype.AddPropertyGroup("Welsh")
        'title
        Dim txtPropType05 = New Umbraco.Core.Models.PropertyType(txtDataTypeDef)
        txtPropType05.Name = "Welsh Title"
        txtPropType05.Alias = "cy_gb_title"
        mediatype.AddPropertyType(txtPropType05, "Welsh")
        'keywords
        Dim txtPropType04 = New Umbraco.Core.Models.PropertyType(txtDataTypeDef)
        txtPropType04.Name = "Welsh Keywords"
        txtPropType04.Alias = "cy_gb_keywords"
        mediatype.AddPropertyType(txtPropType04, "Welsh")
        'description
        Dim txtPropType06 = New Umbraco.Core.Models.PropertyType(txtDataTypeDef)
        txtPropType06.Name = "Welsh Description"
        txtPropType06.Alias = "cy_gb_description"
        mediatype.AddPropertyType(txtPropType06, "Welsh")
    
        cts.Save(mediatype)
    End Sub
    

    Thanks,

    Muiris

Please Sign in or register to post replies

Write your reply to:

Draft