在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
string filepath = "c:\\Fetion2010_3.6.1900.exe"; System.IO.Stream iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; string filename = System.IO.Path.GetFileName(filepath); try { iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); dataToRead = iStream.Length; Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.Charset = "gb2312"; Response.ContentType = "text/xml"; while (dataToRead > 0) { if (Response.IsClientConnected) { length = iStream.Read(buffer, 0, 10000); Response.OutputStream.Write(buffer, 0, length); Response.Flush(); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } Response.Close(); } catch (Exception ex) { Response.Write("Error : " + ex.Message); } finally { if (iStream != null) { iStream.Close(); } } |
请发表评论