<script type="text/javascript">
function openexcel() {
var name = Ext.getCmp('hid_name').getValue();
window.open("outputexcel.aspx?filename=" + name);
}
</script>
public partial class outputexcel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["filename"]))
{
string filename = Request.QueryString["filename"];
string filepath = Server.MapPath("") + @"\..\VideoPlayHistory\" + filename;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Buffer = true;
System.Web.HttpContext.Current.Response.Charset = "UTF-8";
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename); //attachment,下载;inline 在线打开
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
using (Stream stream = new FileStream(filepath, FileMode.Open))
{
using (BinaryReader reader = new BinaryReader(stream))
{
byte[] buffer = new byte[1024 * 32];
int readCount = 0;
while ((readCount = reader.Read(buffer, 0, buffer.Length)) > 0)
{
Response.OutputStream.Write(buffer, 0, readCount);
}
}
//stream.Seek(0, SeekOrigin.Begin);
}
Response.End();
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
}
}
}