Copied to clipboard

Flag this post as spam?

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


  • charlie black 33 posts 106 karma points
    Apr 12, 2014 @ 00:57
    charlie black
    0

    warning CS0618: 'umbraco.cms.businesslogic.media.Media' is obsolete: 'Obsolete, Use Umbraco.Core.Models.Media

    After upgrading from Umbraco 4.7.2 to 6.1.6, compiling code with:

    Media media = new Media(mediaId.Value); 

    generates the warning (above).

    But the advice to "Use Umbraco.Core.Models.Media" is not possible because all the constructors have incompatible signatures. They all start with string and also require additional parameters:

     public Media(string name, IMedia parent, IMediaType contentType)

     public Media(s

    public Media(string name, int parentId, IMediaType contentType)tring name, IMedia parent, IMediaType contentType, PropertyCollection properties)

    public Media(string name, int parentId, IMediaType contentType, PropertyCollection properties)

  • Kevin Jump 2342 posts 14869 karma points MVP 8x c-trib
    Apr 12, 2014 @ 10:52
    Kevin Jump
    0

    Hi

    the warning isn't (quite) pointing you in the right direction.

    in the new API you use the MediaService (Umbraco.Core.Services) so to get a mediaitems.

            var mediaService = ApplicationContext.Current.Services.MediaService;
            IMedia mediaItem = mediaService.GetById(mediaId);
            mediaItem.Name = ...
    
  • charlie black 33 posts 106 karma points
    Apr 14, 2014 @ 18:05
    charlie black
    0

    Kevin-

    Thanks for the help. I've changed the code from this:

                Media media = new Media(mediaId.Value);         

                return media.getProperty("umbracoFile").Value.ToString();

    Now this:

                var mediaService = ApplicationContext.Current.Services.MediaService;

                Umbraco.Core.Models.IMedia mediaItem = mediaService.GetById(mediaId.Value);

                return mediaItem.GetValue("umbracoFile").ToString();

     

    Thanks again!!!!

Please Sign in or register to post replies

Write your reply to:

Draft