Copied to clipboard

Flag this post as spam?

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


  • Aleksey Gerasimov 31 posts 95 karma points
    Feb 09, 2016 @ 14:46
    Aleksey Gerasimov
    0

    IPublishedContent Property Access

    Hi there,

    We're working on update our site from 6.2.4 version to 7.3.7

    We've tried to retrieve and show a property of a IPublishedContent object. Unfortunatly, GetPropertyValue method returns nothing (empty string or null).

    Here is how we trying to use it:

    // This line returns valid array (in our case it contains just one item, but can more)
    var newsItems = Model.Content.Descendants("NewsItem").Where(ni => !ni.GetPropertyValue<bool>("hideOnNewsPage")).OrderByDescending(ni => ni.GetPropertyValue<string>("newsEntryDate")).ToList();
    
    @foreach (var newsItem in newsItems)
                {
                    var link = newsItem.GetPropertyValue<string>("newsEntryExternalLink");
                    counter++;
                    <div class="col-sm-6" style="@(counter % 2 == 0 ? "clear:right;" : "clear:left;")">
    //Next two lines return "True", so we can know that a property really exist
                        <span>@newsItem.HasProperty("newsEntryDate").ToString()</span>
                         <span>@newsItem.HasValue("newsEntryDate").ToString()</span>
    //Next line returns "False", so it means that a value exist
                         <span>@newsItem.IsNull("newsEntryDate").ToString()</span>
    
                        <div class="content-box icon-top-aligned-text">
                            <div class="press-release-icon">
    //Next line represents just empty <em></em> element on the HTML page. Same for all other usages of GetPropertyValue method                      <em>@{newsItem.GetPropertyValue("newsEntryDate").ToString();}</em>                                  
                            </div>
                        </div>
                    </div>
                }
    

    NOTE: HasProperty and HasValue mehods return "True" value, so we'd expect that it will return something else than empty string.

    Also we've tried to use "newsItem.newsEntryDate", however it throws an exception that the Property is undefined.

  • Alessandro Calzavara 32 posts 144 karma points c-trib
    Feb 09, 2016 @ 15:14
    Alessandro Calzavara
    0

    Have you tried to rebuild the cache by republishing the site?

  • Daniel 60 posts 174 karma points
    Feb 09, 2016 @ 17:31
    Daniel
    0

    A nice check is to look in the "/App_Data/umbraco.config" file - there you can see the if the properties you're trying to access exist and have values.

    Like Alessandro says, a republish updates this file.

  • Aleksey Gerasimov 31 posts 95 karma points
    Feb 10, 2016 @ 13:33
    Aleksey Gerasimov
    0

    Hi guys, thanks for your answers.

    Actually, "/App_Data/umbraco.config" file contains correct data about the object. So I'd expect that is should be displayed.

    I've tried to uppublish and publish again, but it's not working for me.

    Do you have any ideas why it can happen?

  • James Jackson-South 489 posts 1747 karma points c-trib
    Feb 11, 2016 @ 07:07
    James Jackson-South
    0

    What happens when you try

    newsItem.GetPropertyValue<string>("newsEntryDate")

  • Aleksey Gerasimov 31 posts 95 karma points
    Feb 11, 2016 @ 09:34
    Aleksey Gerasimov
    0

    Empty as well. Same for the:

    newsItem.GetPropertyValue<DateTime>("newsEntryDate")
    
Please Sign in or register to post replies

Write your reply to:

Draft