private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string filepath = Server.MapPath("\\MyAsp\\WebApplication3\\Books\\a.rm");
Response.AddHeader("content-disposition","attachment;filename=" + "a.rm");
Response.ContentType=@"application/octet-stream";
Response.WriteFile(filepath);
Response.End(); }
{
string filepath = Server.MapPath("\\MyAsp\\WebApplication3\\Books\\a.rm");
Response.AddHeader("content-disposition","attachment;filename=" + "a.rm");
Response.ContentType=@"application/octet-stream";
Response.WriteFile(filepath);
Response.End(); }
不行吗?就算是先读到我的内存也不至于从300M一下到600M ->重起机器才行
{
FileStream fs=new FileStream("d:\\a.rm",FileMode.Open);
byte[] buffer=new byte[(int)fs.Length];
// fs.Read(buffer,0,(int)fs.Length);
// fs.Close ();
// // 下载文件
// Page.Response.AddHeader( "Content-Type", "application/octet-stream" );
// Response.Charset = "GB2312";
// Response.Buffer=true;
// HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(("11.xml")));
//// Response.OutputStream.Write(buffer,0,buffer.Length);
// Response.OutputStream.BeginWrite(buffer,0,buffer.Length,new AsyncCallback(this.MyCallBack),Response.OutputStream);
}
private void MyCallBack(IAsyncResult ar)
{
NetworkStream str=(NetworkStream)ar.AsyncState;
HttpContext.Current.Response.ClearHeaders();
str.EndWrite(ar); }
string serverF= Server.MapPath("\\MyAsp\\WebApplication3\\Books\\a.rm");
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition","attachment;filename=" + "a.rm");
FileStream fs = File.OpenRead(serverF);
byte [] bytes = new Byte[fs.Length];
fs.Read(bytes,0,(int)fs.Length);
fs.Close();
Response.BinaryWrite(bytes);
Response.End();