Posted in: Comments

This is somewhat of a hidden feature in EPiServer. But there is actually a built-in feature to send a download dialog to the user instead of opening the file directly. Soon the download attribute, that you can set on anchors, will work in all browsers but in the meanwhile we can do:

public static string GetDownloadLink(this ContentReference contentReferenceToMediaFile)
{
    var url = UrlResolver.Current.GetUrl(contentReferenceToMediaFile);

    return url + "/download";
}

The important part here is of course /download. For images you can add /thumbnail (or the name of another blob property) to get the thumbnail of the image.