首先入口是abc.aspx,从某个GridView的OnRowCommand开始:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int iIdx = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "Print")
{
//Session["PrintFileID"] = GridView1.DataKeys[iIdx]["流水号"].ToString();
string sLiuShuiID= GridView1.DataKeys[iIdx]["流水号"].ToString();
Response.Write("<script>window.open('SendFileNew.aspx?id=" + sLiuShuiID + "')</script>");
}
}ShowFile.aspx的page_load事件里有:
string sPath = dt.Rows[0]["附件"].ToString(); // 如果有附件
if (sPath != "")
{
sPath = Server.MapPath("~") + sPath;
Session["AttachmentPath"] = sPath; // 暂用Session传
Response.Write("<script>window.open('PrintAttachment.aspx')</script>");
}PrintAttachment.aspx的page_load事件里有:
string sPath = Session["AttachmentPath"].ToString();
FileInfo DownloadFile = new FileInfo(sPath);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}我选了一个有附件的文件,ShowFile.aspx都顺利弹出,同时应该会弹出PrintAttachment.aspx并出现"打开","保存"的那个对话框,有些电脑上可以正常显示PrintAttachment.aspx,但是很多电脑上PrintAttachment.aspx闪了一下就自己关了,估计是IE设置的问题,我调了半天也没弄好..本来以为是拦截弹出窗口的问题,但是一想:既然ShowFile.aspx可以弹出,为什么PrintAttachment.aspx不行..不是拦截窗口的问题..那是为什么呢?
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int iIdx = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "Print")
{
//Session["PrintFileID"] = GridView1.DataKeys[iIdx]["流水号"].ToString();
string sLiuShuiID= GridView1.DataKeys[iIdx]["流水号"].ToString();
Response.Write("<script>window.open('SendFileNew.aspx?id=" + sLiuShuiID + "')</script>");
}
}ShowFile.aspx的page_load事件里有:
string sPath = dt.Rows[0]["附件"].ToString(); // 如果有附件
if (sPath != "")
{
sPath = Server.MapPath("~") + sPath;
Session["AttachmentPath"] = sPath; // 暂用Session传
Response.Write("<script>window.open('PrintAttachment.aspx')</script>");
}PrintAttachment.aspx的page_load事件里有:
string sPath = Session["AttachmentPath"].ToString();
FileInfo DownloadFile = new FileInfo(sPath);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}我选了一个有附件的文件,ShowFile.aspx都顺利弹出,同时应该会弹出PrintAttachment.aspx并出现"打开","保存"的那个对话框,有些电脑上可以正常显示PrintAttachment.aspx,但是很多电脑上PrintAttachment.aspx闪了一下就自己关了,估计是IE设置的问题,我调了半天也没弄好..本来以为是拦截弹出窗口的问题,但是一想:既然ShowFile.aspx可以弹出,为什么PrintAttachment.aspx不行..不是拦截窗口的问题..那是为什么呢?
Response.AppendHeader("Content-Disposition", "attachment;filename=" +应该弹出提示是否保存文件的窗口不对嘛?
有些电脑可以弹出提示是否保存文件的窗口,有些不弹出
我没设置时间,PrintAttachment.aspx在某些电脑上一直显示,但很多电脑上闪1-2秒,还没弹出提示是否保存文件的小窗口就关闭了我想应该不是弹出时间的问题,现在机房没VS,等下回去还是试试