sql = "select CardName,CardPass,isUse,CardType,Datatime,isExport from Card where isExport='0'";
            SqlConnection con = Db.GetDb();
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            da.Fill(ds, "123");            string path = Server.MapPath("flysoblog.txt");   //根当前程序放在同一个目录   
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            if (!File.Exists(path))
            {
                File.Create(path).Close();
            }
            //生成文本文件的路径   
            FileStream fsobj = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fsobj, System.Text.UnicodeEncoding.Unicode);
            DataTable dt = ds.Tables["123"];
            sw.Write("\0\0\0" + "学生卡号" + "\0\0\0\0\0\0\0\0\0\0\0\0学生密码" + "\0\0\0\0\0\0卡号类型\0\0\0\0\0\0使用情况\0\0\0\0生成时间\r\n");
            sw.Write("-------------------------------------------------------------------------\r\n");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sw.Write(dt.Rows[i]["CardName"].ToString().Trim() + "\0\0\0");
                sw.Write(dt.Rows[i]["CardPass"].ToString().Trim() + "\0\0\0");                using (SqlConnection conn = Db.GetDb())
                {
                    string sqln = "update Card set isExport=1 where CardName=@CarName";
                    SqlCommand annd = new SqlCommand(sqln, conn);
                    annd.Parameters.Add("@CarName", SqlDbType.VarChar).Value = dt.Rows[i]["CardName"].ToString().Trim();                    conn.Open();
                    annd.ExecuteNonQuery();
                    annd.Clone();                }                sw.Write(dt.Rows[i]["CardType"].ToString().Trim() + "\0\0\0");
                string isSy = string.Empty;
                isSy = dt.Rows[i]["isUse"].ToString().Trim();
                if (isSy.ToLower().Equals("true"))
                {
                    isSy = "\0\0\0\0\0已使用\0";
                }
                else
                {
                    isSy = "\0\0\0\0\0未使用\0";
                }
                sw.Write(isSy + "\0\0\0");
                sw.Write(dt.Rows[i]["DataTime"].ToString().Trim() + "\0\0\0");
                sw.Write("\r\n");
                
            }
            //循环输出内容以及格式
            con.Close();
            sw.Close();
            fsobj.Close();
            sw.Dispose();
            fsobj.Dispose();
            string contentType = "application/";
            string filename = "flysonetCard.txt";
            System.Diagnostics.Process.Start("notepad.exe", "学习卡-" + System.DateTime.Now.ToString("yyyy年mm月dd日") + ".txt");
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.ContentType = contentType;
            HttpContext.Current.Response.WriteFile(path);
            HttpContext.Current.Response.End();
            //执行完上面的代码之后  我想跳转到别的页面 
            //这是一个点击按钮另存为 之后再跳转到别的页面
            //请详细代码告诉我 谢谢老鸟

解决方案 »

  1.   

    应该是不能在做跳转了,原因在于以下这句:
    HttpContext.Current.Response.End();
      

  2.   

    LZ可以尝试将HttpContext.Current.Response.End();注释,加上跳转的执行代码,试试
      

  3.   

    触发时一个button 之后执行代码 跳转页面
    上面说的我都用过了 研究了一下午了 直接跳转不行 别猜
      

  4.   

    Response.End();不能继续向客户端发送信息
    可在其他页面DownLoadFiles.aspx下载文件
      

  5.   

    Response.ContentType = "image/jpeg";
    Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg");
    Response.TransmitFile( Server.MapPath("~/images/sailbig.jpg") );
    Response.End();
    Me.Response.Redirect(URL)
      

  6.   

    Response.End();//请用   HttpContext.Current.ApplicationInstance.CompleteRequest() 替换
                Response.Redirect("page.aspx");//请用   Response.Redirect("page.aspx",false); 替换
                //只要不在页面中使用Response.End();就不会出现线程中止异常.
                //Response.Redirect("page.aspx");默认调用了Response.End();
                //使用重载传入false可以不调用Response.End();而不出现此异常
      

  7.   

    Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End。
     解决方案
    要解决此问题,请使用下列方法之一:
    • 对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行。
    • 对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如:
      Response.Redirect ("nextpage.aspx", false);
                
    如果使用此替代方法,将执行 Response.Redirect 后面的代码。
    • 对于 Server.Transfer,请改用 Server.Execute 方法。