Get image by front end url - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Get image by front end url

  • Get image by front end url
  • 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;