In our application we have an excel (xlsx/xls) file in medial library. We are trying to create a functionality to be able to download this excel using an html anchor or button.
But when we click on the achor/button, we get erro "The requested document was not found"
Currently I have following changes done but it’s not working. Please suggest right approach to do this.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <settings> <setting patch:instead="setting[@name='Media.RequestExtension']" name="Media.RequestExtension" value=""/> </settings> </sitecore> </configuration>
2. View(cshtml) code
< a href="http://xyx.com/-/media/TCW/Dotcom/TestFactSheet.xlsx" />
3. Controller code to get the media Url
var factSheetItem = SitecoreContext.GetItem<Item>(usPage.MorningStarFactSheetLink.Id); MediaUrlOptions mediaOptions= new MediaUrlOptions(); mediaOptions.AlwaysIncludeServerUrl = true; mediaOptions.AbsolutePath =true; var mediaItemUrl = MediaManager.GetMediaUrl(factSheetItem, mediaOptions); vm.Fields.MorningStarFactSheetLink = mediaItemUrl;
- We have tried file/General Link Field Types for Template field
Note: we are facing this issue for all types of files pdf/excel not just excel.
Please do suggest correct approach to implement it.