How to force file download on Telerik RadEditor?
I am using Document Manager in Telerik RadEditor.
Once I upload .txt file and click on that link, it opens on the browser instead of downloading it. How to force download that file without going in to .htaccess 开发者_C百科or other server changes?
Short answer is: using RadEditor alone you can't.
In order to make a browser-viewable file type be served as a download you must send it to the client's browser with a 'Content-Disposition' type of 'attachment'. Doing so is fairly simple, however it requires server-side code that would be outside of the scope of RadEditor.
var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/path/to/file.txt"));
Response.AddHeader("Content-Type", "text/plain");
Response.AddHeader("Content-Displosition", "attachment;filename=file.txt;size=" + bytes.Length);
Response.Flush();
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
Unless you want to write a specific handler for serving the file in question, your only option is to instruct users that they must 'Right-Click > Save Link As...' on your text file link.
精彩评论