Search code examples
sensenet

Sense/Net download text file


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?


Solution

  • 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.