关于ASP.net页面下载
写了个下载页面,可用的时候,不知怎的,总会先弹出一个空白页面,在弹出下载的对话框。执行下载操作后,空白页面也不消失。希望有高手大大能给看看~~private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (Request.Params["id"] != null&&Request.Params["id"].ToString().Trim()!="")
{
int id=int.Parse(Request.Params["id"].ToString().Trim());
string strAttachmentSql="select * from OPRT_NOTICESENDADJUNCT where F_NOTICEID="+id;
string strFileName = "";
byte[] outByte = new byte[260000];
string filename = "";
string ExtensionName = "";
DataTable dtAttach = DBOperationOracle.GetDataTable( strAttachmentSql, DBConnection.GetConnectionString() );
if( dtAttach != null && dtAttach.Rows.Count >0 )
{
strFileName = SysFunction.ObjectToString(dtAttach.Rows[0]["F_NAME"]);
string[] strfilename = strFileName.Split('.');
filename = strFileName;
ExtensionName = "."+strfilename[1];
outByte=(byte[])dtAttach.Rows[0]["F_ADJUNCT"];
}
Response.Clear();
//Response.Write("<table align='center'><tr valign='middle'><td><font size='6' color='#0066cc'>数据正在缓冲,请稍等!</font></td></tr></table>");
Response.BufferOutput = true;
Response.AddFileDependency(filename);
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
Response.ContentType = GetContentType(ExtensionName);
Response.OutputStream.Write(outByte, 0, outByte.Length);
Response.End();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region 判断附件后缀类型
private string GetContentType(string strSuffix)
{
string strResturn = "text/html";
switch (strSuffix)
{
case ".bmp":
strResturn = "image/jpeg";
break;
case ".jpg":
strResturn = "image/jpeg";
break;
case ".gif":
strResturn = "image/jpeg";
break;
case ".doc":
case ".wps":
case ".eio":
strResturn = "application/msword";
break;
case ".xls":
strResturn = "application/vnd.ms-excel";
break;
case ".xml":
strResturn = "text/xml";
break;
case ".ppt":
strResturn = "application/vnd.ms-powerpoint";
break;
case ".rar":
case ".zip":
strResturn = "application/octet-stream";
break;
case ".wav":
case ".avi":
strResturn = "video/x-msvideo";
break;
case ".mpeg":
case ".mpg":
strResturn = "video/mpeg";
break;
}
return strResturn;
}
#endregion
补充:.NET技术 , ASP.NET