You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6 KiB
C#

12 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using DSWeb.EntityDA;
namespace DSWeb.Reports
{
public partial class FileExport : System.Web.UI.Page
{
public string strUserID;//用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
public string filename = "";
protected void Page_Load(object sender, EventArgs e)
{
#region 基本信息
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Request.QueryString["filename"] != null)
{
filename = Request.QueryString["filename"].ToString();
}
if (!IsPostBack)
{
FileExporthtml(filename);
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>window.close();</script>");
//
}
#endregion
}
#region
protected void FileExporthtml(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fs.Close();
MemoryStream ms = new MemoryStream(data);
filename = Path.GetFileName(filename);
RenderToBrowser(ms, Context, filename);
}
public static void RenderToBrowser(MemoryStream ms, HttpContext context, string fileName)
{
if (context.Request.Browser.Browser == "IE")
fileName = HttpUtility.UrlEncode(fileName);
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
context.Response.AddHeader("Content-Disposition", "attachment;fileName=" + fileName);
context.Response.ContentType = "application/txt";
context.Response.BinaryWrite(ms.ToArray());
context.Response.End();
}
#endregion
}
}