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

Forums / Developing with Sitefinity / Image URL replacement

Image URL replacement

2 posts, 0 answered
  1. Gary
    Gary avatar
    7 posts
    Registered:
    27 Mar 2014
    29 Apr 2014
    Link to this post

    I am trying to expose some content for a NewsItem for an external application.  I would like to return all the content of a news item.  I can retrieve the content easy enough, however images look something like this:  <img src="[images|OpenAccessDataProvider]80373ee1-f441-6e81-b252-ff0000757d21" />

    Is there a quick API where I can pass it a content string and get the content back with the actual URLs replaced?

    I have an approach so far but it would be nice if there was something easier (or perhaps more efficient).  Currently I do something like this:

    1.  Retrieve the NewsItems using App.WorkWith().NewsItems().Published().Get()

    2.  Search through NewItem.Content looking for <img src="[images|OpenAccessDataProvider]...

    3.  Get the GUID in the SRC attribute.

    4.  Use the LibraryManager to get the image URL:

    LibrariesManager librariesManager = LibrariesManager.GetManager();
    Image image = librariesManager.GetImages().Where(i => i.Id == id).FirstOrDefault();
    var url = image.MediaUrl;

    5.   Replace the image src with the URL from the .MediaURL.

    Are there any shortcuts to this or any other helper APIs in the SDK?

     

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    02 May 2014
    Link to this post
    Hello Gary,

    This is the correct approach. The image url in the content of the news Item could be get by parsing the image id and than get the Item and the properties you need.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered