aspx file download it is not difficult to say, but in the process of doing still encountered some small problems, because these small problems, resulting in the solution is too difficult, one of which is response.end (), causing the download file thread termination of the situation ...
The correct way to download the file
1 //get the contents of the corresponding file, the main comm. FileURL file Save dynamic Path, i.e. 20150825/5e7af276b7754363a1e78b496e1d1603 text document. txt2Commnoticemodel comm = Commnoticebll.getinstance (). Getcommnoticemodel (int. Parse (request.querystring["ID"]));3 //here the main composition of the relative path of the file, here is the ~/filebox/20150825/5e7af276b7754363a1e78b496e1d1603 text document. txt4 stringPath = Commonutilmodel.getfilevirtualpath () +Comm. FileURL;5 Try6 {7 8FileInfo FileInfo =NewFileInfo (Server.MapPath (path));9 response.clear ();Ten response.clearcontent (); One response.clearheaders (); AResponse.AddHeader ("content-disposition","attachment;filename="+fileinfo.name); -Response.AddHeader ("Content-length", fileInfo.Length.ToString ()); -Response.AddHeader ("content-transfer-encoding","binary"); the //tell the browser to pass to the user is a non-txt,rar, etc. does not appear on the Ieem of a file, do not need to open in the browser page, need to download directly -Response.ContentType ="Application/octet-stream"; -response.contentencoding = System.Text.Encoding.GetEncoding ("gb2312"); - Response.WriteFile (fileinfo.fullname); + Response.Flush (); - Response.End (); + } A at Catch(Exception ex) - { - response.clear (); - response.clearcontent (); - response.clearheaders (); -Response.Write (ex. Message +"<br/>"+path); in Response.End (); -}
Reprint Please specify source: http://www.cnblogs.com/abc1069/
ASP. net file Download (txt,rar,pdf,word,excel,ppt)