Retrieve image and image thumbnail URL

You can programmatically retrieve the media URL or the thumbnail URL of an image using the image ID.

Retrieve media URL

You use the following code to retrieve the media URL of an image. The ID argument is assigned to the master version of the image.

C#
using System;
using System.Linq;
using Telerik.Sitefinity.Modules.Libraries;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.Images
{
    public partial class ImageSnippets
    {
        public static string GetMediaUrlByImageId(Guid masterImageId, bool resolveAsAbsolutUrl)
        {
            var manager = LibrariesManager.GetManager();

            // Get the master version of the image
            var image = manager.GetImages().FirstOrDefault(i => i.Id == masterImageId);

            var mediaUlr = String.Empty;

            if (image != null)
            {
                // Resolve the media URL
                mediaUlr = image.ResolveMediaUrl(resolveAsAbsolutUrl);
            }

            return mediaUlr;
        }
    }
}

In the code above, you first get an instance of the libraries manager. Next, you get the specified image by its master ID. If the image is found, the ResolveMediaUrl method of the image item is called and returns the media URL of the image.

Retrieve thumbnail URL

To retrieve image thumbnail URLs you must use the ResolveThumbnailUrlextension method of the Telerik.Sitefinity.Modules.Libraries namesapce. For more information about the method usage refer to the Retrieve media content thumbnail URLs article.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.