Copied to clipboard

Flag this post as spam?

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


  • Jerker Stigsson 63 posts 122 karma points
    Dec 02, 2013 @ 00:32
    Jerker Stigsson
    0

    Custom Media property problem

    I try to use a custom Media property. But I get:

    Object not set to an instance of an object.

    The x.GetPropertyValue doesn't find the custom Media properties at all. Does anyone know how to go about this?

    I use ver 6.1.5

    var rootMedia = Umbraco.TypedMediaAtRoot();
    
    var rootFiles = rootMedia.Select(x => x)
        .Where(x => x.DocumentTypeAlias == "File" && x.GetPropertyValue("umbracoExtension").ToString().Contains("pdf"));
    
    var descendantFiles = rootMedia.SelectMany(x => x.Descendants())
        .Where(x => x.DocumentTypeAlias == "File" && x.GetPropertyValue("umbracoExtension").ToString().Contains("pdf"));
    
    var oFiles = rootFiles.Union(descendantFiles)
        .Where(x => x.GetPropertyValue("documentMetaData").ToString().Contains(metadata_id))
        .OrderByDescending(x => x.CreateDate);
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2013 @ 11:47
    Jeavon Leopold
    0

    Hi Jerker,

    I had no problem getting the below sample to work with Umbraco v6.1.6, (I only made a few small tweaks, but your original sample worked also). What do you have in the variable metadata_id?

    @{
        var rootMedia = Umbraco.TypedMediaAtRoot();
    
        var rootFiles = rootMedia.Select(x => x)
            .Where(x => x.DocumentTypeAlias == "File" && x.GetPropertyValue<string>("umbracoExtension").Contains("pdf"));
    
        var descendantFiles = rootMedia.SelectMany(x => x.Descendants())
            .Where(x => x.DocumentTypeAlias == "File" && x.GetPropertyValue<string>("umbracoExtension").Contains("pdf"));
    
        var oFiles = rootFiles.Union(descendantFiles)
            .Where(x => x.GetPropertyValue<string>("documentMetaData").Contains("something"))
            .OrderByDescending(x => x.CreateDate);
    }
    <p>@oFiles.Count()</p>
    

    Jeavon

  • 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