在使用sivlerlight 嵌套 JS的方式实现文件下载的过程中,发现了这样的一个问题:
在执行handle.ashx的时候,不提示IE自身的文件下载弹出框,求解释。
使用Chrome浏览器可以下载,本人使用的SL4+IE8.
1 public void ProcessRequest(HttpContext context) 2 { 3 String tmpfileName = context.Request.QueryString["FileName"]; 4 5 string fileName = UnicodeConvert.FromUnicode(tmpfileName); ; 6 string filePath = AppDomain.CurrentDomain.BaseDirectory + fileName; 7 System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); 8 if (fileInfo.Exists == true) 9 { 10 byte[] buffer = new byte[ChunkSize]; 11 12 context.Response.Clear(); 13 14 FileStream iStream = File.OpenRead(filePath); 15 long dataLengthToRead = iStream.Length; //获取下载的文件总大小 16 context.Response.AddHeader("Content-Disposition", "attachment; filename=" + 17 fileInfo.FullName); 18 19 context.Response.ContentType = "application/octet-stream"; 20 context.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); 21 22 while (dataLengthToRead > 0 && context.Response.IsClientConnected) 23 { 24 int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(102400));//'读取的大小 25 26 context.Response.OutputStream.Write(buffer, 0, lengthRead); 27 context.Response.Flush(); 28 dataLengthToRead = dataLengthToRead - lengthRead; 29 } 30 //context.Response.Close(); 31 context.Response.End();