Media library: Get Image URL for pages Programmatically

Chaudhary Zulfiqar asked on December 7, 2015 23:25

Hi, I am trying to link the bio pages to the media image library while importing the Bio's using Kentico Import API's. My question is how do I create a link between the image from the media library to the bio page pro-grammatically while using the specific height and width of the image URL as well. I did that via the kentico interface i.e. select image on BIO page it creates the following URL to link to the bio page. "/getmedia/2919ccd1-69e0-42f1-9912-e5a4ce4f73f4/firstname-lastname?width=350&height=350&ext=.jpg"

How do I create that image URL link with height and width pro-grammatically while importing all the bio's in kentico 8.2.

Thank you

Recent Answers

Timothy Fenton answered on December 15, 2015 03:59

Hello Chaudhary I am not sure what you mean by "Bio page" are you referring to the details page for each individual user? Or is Bio some custom page type? If you have the MediaFileInfo object you could simply build the url using everything inside the object, something like this:

string url = MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName);
url = URLHelper.AddParameterToUrl(url, "width", mfi.FileImageWidth.ToString());
url = URLHelper.AddParameterToUrl(url, "height", mfi.FileImageHeight.ToString());
url = URLHelper.AddParameterToUrl(url, "ext", mfi.FileExtension);
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.