Reputation: 555
I have a couple of unversioned PDFs in the media library... when I try opening them up from their URLs, it says "Layout not found". When I assign a layout (any layout), it just doesn't render anything.
I've added forcedownload=true to the media library section of the web.config... is there anything I'm missing? I thought this was supposed to download by default
http://testsite.org/sitecore/media%20library/pdfs/Publications/Periodicals/Test
The URL above basically doesn't work
Upvotes: 0
Views: 1020
Reputation: 17000
Links to items in the media library are usually prefixed with /~/media/
, unless you have changed the value of Media.MediaLinkPrefix
in config. The link should be something like:
http://testsite.org/~/media/pdfs/Publications/Periodicals/Test.pdf
Make sure you are generating the URLs using MediaManager.GetMediaUrl()
FileField fileField = Sitecore.Context.Item.Fields["File Field"];
var mediaItem = new MediaItem(fileField.MediaItem);
string url = Sitecore.StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(fileMediaItem));
Always use LinkManager.GetItemUrl()
for items and MediaManager.GetMediaUrl()
for media items to generate Sitecore URLs.
Upvotes: 3
Reputation: 1879
//below is the code to specify an Image URL
MediaItem mediaItem = new MediaItem(Sitecore.Context.Database.GetItem("Path"));
if (mediaItem != null)
{
imgBtn.ImageUrl = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
imgBtn.AlternateText = mediaItem.Alt;
}
Upvotes: 0
Reputation: 3064
You don't have to assign a layout to media item. Make sure you add "/" prefix before the url. Ex: site/~/media/path to pdf.ashx.
Also make sure you have media files published.
Upvotes: 0