1

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.

1.Config Setting

  <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;
  1. 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.

I get below error screen. enter image description here

Please do suggest correct approach to implement it.

5
  • Take a look at sitecore.stackexchange.com/questions/7790/… Alternativelty here: sitecore.stackexchange.com/questions/134/…
    – Mark Cassidy
    Sep 10 '18 at 21:15
  • When you say it doesn't work. What do you mean? It doesn't output the right extension, the link doesn't work? Also, are you having issues with normal images such as jpg etc.? The view code seems to be also the rendered view, not what's in the view file, that could be useful. Sep 10 '18 at 21:15
  • When i say its not working, I mean when we click on link to download excel-sheet, it show error "The requested document was not found" Sep 10 '18 at 22:13
  • Can you check the output screen and see if you are able to see the desired link in the anchor tag. Sep 11 '18 at 5:57
  • Have you published the media library?
    – jammykam
    Sep 11 '18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.