I have a function that automatically creates PDF files in the sitecore Media Library. I want to display a link on another webpage to download or view this PDF.
Sitecore.Data.Database context= Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.MediaItem item = (Sitecore.Data.Items.MediaItem)context.GetItem("/sitecore/Media Library/Requests/"+ddlRequests.SelectedValue+".pdf");
To get the item link I use the following line. This line won't execute appearently.
Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
Any Ideas what I'm doing wrong here?
It looks like your code should work just fine without the .pdf
in the query. Select one of the pdf files in Media Library and on the content
tab check what is the value of Item Path
property. This is what you should use in the query (so most probably without .pdf
):
Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.MediaItem item = (Sitecore.Data.Items.MediaItem)db.GetItem("/sitecore/Media Library/Requests/" + ddlRequests.SelectedValue);
Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);