Get image by front end url

Posted by Community Admin on 04-Aug-2018 22:36

Get image by front end url

All Replies

Posted by Community Admin on 04-Apr-2017 00:00

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;

 

 

 

This thread is closed