1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get image by front end url

Get image by front end url

1 posts, 0 answered
  1. Scott
    Scott avatar
    5 posts
    Registered:
    11 Aug 2014
    04 Apr
    Link to this post

    I am trying to get an image based on the rendered "src" tag  of an image in a blog.  I was able to get it work, wondering if there is a better to accomplish it without the loop and splitting the "src" path.

     

    string[] pathArray = path.Split('/');
     
                 
                   string albumName = pathArray[pathArray.Length -2];
                   string itemName = pathArray[pathArray.Length - 1].Substring(0, pathArray[pathArray.Length - 1].IndexOf('.'));
                   var domain = HttpContext.Current.Request.Url.ToString().Replace(HttpContext.Current.Request.Url.AbsolutePath.ToString(), "").Trim();
     
                   var imageVersions = App.WorkWith().Albums().Where(a => a.Title.Equals(albumName)).Get().FirstOrDefault().Images().Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live &&  i.UrlName.Equals(itemName));
     
     
                   foreach (Telerik.Sitefinity.Libraries.Model.Image image in imageVersions)
                   {
                       var imageUrl = image.ResolveMediaUrl(false).Replace(domain, " ");
                       if (imageUrl == path)
                       {
                           return image;
                       }
                   }
     
               return null;

     

     

     

1 posts, 0 answered