When I try to download the text file in sensenet, the text file will open in browser but not downloaded, could you give some suggestions about how to set to download text file directly?
-
Maybe needs to add some code in ActionLinkButton::Rander http://stackoverflow.com/questions/17527713/force-browser-to-download-image-files-on-click – Frank Yuan May 18 '17 at 10:53
-
For IE, need more code, such as href="<%=Actions.ActionUrl(content, actionName)%>"><%= HttpUtility.HtmlEncode(content.DisplayName) %> – Frank Yuan Sep 19 '17 at 09:50
1 Answers
It's handled by the browser. If it can open a certain file type, then it will show it instead of downloading.
On server side you can force to download file types on your website if your http handler use disposition when set response stream:
response.AppendHeader("Content-Disposition", "attachment");
With sensenet you have to write your own http handler or modify ProcessRequest of SenseNetStaticFileHandler.cs. MSDN is not too helpful on this topic, but you can find some information on this here.
On client side there is another solution, if you can change the html code of the link. With html5 <a>
tag has got a download
attribute that forces the linked file to download instead of navigate the browser to it. It works if the browser supports it. See HTML download Attribute.

- 175
- 5
- 10
-
-
Thanks, I tried download attribute in tag, but seems like not work in IE. So I add some other code like above. – Frank Yuan Mar 23 '18 at 09:49
-
Yeah! IE is a bit outdated and so it doesn't support download tag (though Edge does), so with older browsers you need a workaround to behave differently with different browsers. Maybe this method works as written on this page https://webdesign.tutsplus.com/tutorials/quick-tip-using-the-html5-download-attribute--cms-23880 – VargaJoe Mar 23 '18 at 10:00
-