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 ?
Like Johan says here:http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=78865&epslanguage=en
"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.)"
That indicates you don't have enough access rights for the file. Is it published?
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)
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();
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 ?
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
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
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.
Great that you found out the solution and good to have it here if there are anyone else that will see the same error