More in this section
Forums / Developing with Sitefinity / Unable to access related media in other environments

Unable to access related media in other environments

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. Don
    Don avatar
    0 posts
    Registered:
    05 Jun 2017
    19 Jun 2017
    Link to this post

    I have the following code which works fine for getting the media URL of a single image field on my local machine, but when I move the code to our staging environment and create new content, it acts like there is no related image (GetValue returns null):

     

                var model = new SportsNewsModel { NewsItems = new List<SportsNewsItem>() };
                var topNews = GetDynamicContentItems("Telerik.Sitefinity.DynamicTypes.Model.ClackamasNews.Article")
                    .Where(i => i.FieldValue<string[]>("Categories").Contains("2"))
                    .OrderByDescending(i => i.GetValue<DateTime?>("ArticleDate"))
                    .Take(2);

                foreach (var i in topNews)
                {
                    var sportsNewsItem = new SportsNewsItem();
                    var imageField = i.GetValue<Image>("ArticleImage");

                    sportsNewsItem.Headline = i.GetString("Title").ToString();
                    sportsNewsItem.NewsPath = i.ItemDefaultUrl;
                    sportsNewsItem.PublishDate = i.GetValue<DateTime?>("ArticleDate").Value;
                    sportsNewsItem.ImagePath = imageField != null ? imageField.MediaUrl : string.Empty;

                    model.NewsItems.Add(sportsNewsItem);
                }

                return View("Default", model);

1 posts, 0 answered