Copied to clipboard

Flag this post as spam?

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

  • Marco Lusini 176 posts 1370 karma points
    Feb 10, 2018 @ 08:17
    Marco Lusini

    Uninstall package and Media Types


    I am trying to uninstall the package and remove the media types that it creates from a production site. Is there a way to change media created as type File-Word, File-Pdf, etc. to the standard File type without other side effects?

    TIA Marco

  • Andy Robinson 9 posts 96 karma points c-trib
    Feb 11, 2018 @ 14:27
    Andy Robinson

    Hi Marco, it seemed like a great idea at the time, but since then umbraco killed off the ability to access child media types

    here is a Gits that will set the mediatypes back to "File" when you save a media type

  • Marco Lusini 176 posts 1370 karma points
    Feb 13, 2018 @ 10:40
    Marco Lusini

    Thanks! I used your example as a basis for a template that changes each media of type File-xxx to File (to be run after the package is uninstalled):

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Umbraco.Core;
    @using Umbraco.Core.Logging;
    @using Umbraco.Core.Models;
    @using Umbraco.Core.Services;
        Layout = null;
        IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
        IContentTypeService contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
        IMediaType fileMediaType = contentTypeService.GetMediaType("File");
        <title>Media Type changer</title>
        <h1>Convert File children types to File type</h1>
        @foreach (IMediaType subFileType in contentTypeService.GetMediaTypeChildren(fileMediaType.Id))
            <h2>Converting @subFileType.Name to @fileMediaType.Name</h2>
            IEnumerable<IMedia> filesToConvert = mediaService.GetMediaOfMediaType(subFileType.Id);
            int cnt = 0;
            foreach (IMedia file in filesToConvert)
                <p>@cnt/@filesToConvert.Count() - @file.Name converted to @fileMediaType.Name</p>
Please Sign in or register to post replies

Write your reply to: