c# - jQuery / javascript download file doesn't work on Chrome -
i have jquery script in want download file located on server after user clicks on link. on ie11 works alright, make call to:
window.open('file:///myserver0001/somefolder/tmp/toiletflush.log'
i know security reasons, chrome doesn't allow use protocol file:/// . interesting because if write myself url on address bar show file, if make call window.open() opens me new empty window. also, removing file:/// , doesn't on chrome, says page not available
so right don't know how make work on chromium. thought make workaround calling controller function through post/get , return fileresult , download file. works know simple way directly using jquery/javascript.
any idea?
try asp.net mvc fileresult:
view:
<a href='@url.action('getfile','home')">download file</a>
in home controller:
public fileresult getfile() { //read file content variable. string content=file.readalltext("filepath"); byte[] bytearray = encoding.ascii.getbytes(content); return file(bytearray, system.net.mime.mediatypenames.text.plain, "toiletflush.log"); }
Comments
Post a Comment