Direct download link to MediaData type file


I do have a pdf file of MediaData type. When I try to access it via it's VirtualPath, redirected to "login/CMS/edit/PreviewContainerPage.aspx" page it says "Preview is not available for this page"

So, is there any way to get direct link to this pdf file ?

Jun 10, 2014 12:30

Like Johan says here:

"You could use UrlResolver (resides in EPiServer.Web namespace), you can either get an instance from IOC container or use static property Current. 

UrlResolver have several overloaded methods GetUrl that returns links. The most basic one takes a single ContentReference and returns the url in the same format as the current context is executing (so if the code executes on site the url will be public while if the code is executign e.g. in onpageedit mode the url will be in edit format.)"

Jun 10, 2014 12:53

That indicates you don't have enough access rights for the file. Is it published?


Jun 10, 2014 13:29

Thanks Henrik & Frederik for your reply


Yes, i'm using


to get the file path. But when try to access the pdf file using path return by the UrlResolver i'm getting above "Preview is not available for this page" thing. So, i just wanted to know how can fix this


It has read access to everyone. What do you mean by "Is it published?". I have drag and drop this pdf file in to a media folder in the EpiServer site. didn't do any sort of publish initially. (do publish only if I have change some content setting of the file in the edit mode)

Jun 10, 2014 15:29


Please try an extension method in EPiServer.Cms.Shell.dll (EPiServer.Cms.Shell.IContentExtensions) like this:

var mediaContent = _contentRepository.Get<IContent>(contentLink);
var directDownloadUrl = mediaContent.DownloadUrl();

//Ha Bui

Jun 11, 2014 6:32

Thanks Habu for your reply

I have used the "DownloadUrl()". But still redirected to "login/CMS/edit/PreviewContainerPage.aspx" page having "Preview is not available for this page" text

Did I missing something here ?

Jun 11, 2014 8:14

It's strange that when we deployed same code in to staging server, things working perfectly (able to download/view pdf file). But this is not working in local dev environment

So, actually


 working fine in the staging environment and able to access the file. But in the local dev environment always getting "Preview is not available for this page"

Confused a lot with this matter and haven't have any idea about this behaviour

Jun 11, 2014 20:13

Finally found the root cause. In the dev environment "MVC Template" setting of "Display Template" in "DocumentMedia" (where pdf falls) Media Type is set to "DefaultMediaPreviewController". Just clearing out that value (letting it blank) resolve the issue.

Edited, Jun 11, 2014 21:07

Great that you found out the solution and good to have it here if there are anyone else that will see the same error

Jun 12, 2014 7:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.