c# - Download with chunks. Need to stop page loading in order to start download with Internet Download Manager -
i using following code download huge (around 2 gb) files.
view code
<a href="/checkdownload/index">download</a>
controller-action method code
code download file in chunks.
public actionresult index() { system.io.stream istream = null; // buffer read 10k bytes in chunk: byte[] buffer = new byte[10000]; int length; long datatoread; //creates whole path clicked file resides. string finalpath = @"e:\builds\sharepoint\fileabc.csv"; string filename = system.io.path.getfilename(finalpath); try { istream = new system.io.filestream(finalpath, system.io.filemode.open, system.io.fileaccess.read, system.io.fileshare.read); // total bytes read: datatoread = istream.length; response.contenttype = "application/octet-stream"; response.addheader("content-disposition", "attachment; filename=" + filename); //response.addheader("connection", "keep-alive"); // read bytes. while (datatoread > 0) { // verify client connected. if (response.isclientconnected) { // read data in buffer. length = istream.read(buffer, 0, 10000); // write data current output stream. response.outputstream.write(buffer, 0, length); // flush data html output. response.flush(); buffer = new byte[10000]; datatoread = datatoread - length; } else { //prevent infinite loop if user disconnects datatoread = -1; } } } catch (exception e) { //return view(); } { if (istream != null) { //close file. istream.close(); } response.close(); } return view(); }
when try use internet download manager(idm) in order download, opens new tab , until stop loading page, download not start , idm shows connecting. when stop page load, download starts idm.
while in normal download via browser, starts download.
what reason it? new framework, appreciated.
update
i noticed happening in chrome , not internet explorer.
Comments
Post a Comment