page.Response.WriteFile(newpath);

page.Response.Clear();
            page.Response.ClearHeaders();
            page.Response.Buffer = false;
            page.Response.Charset = "UTF-8";
            page.Response.ContentType = "application/ms-excel";
            page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + page.Server.UrlEncode(nf.Name));
            page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            page.Response.ContentEncoding = System.Text.Encoding.Default;
            page.Response.AppendHeader("Content-Length", nf.Length.ToString());
            page.Response.Charset = "";
            page.EnableViewState = true;
            page.Response.BufferOutput = false;
            page.Response.WriteFile(newpath);
            //删除创建的Excel文件
            if (File.Exists(newpath)) File.Delete(newpath);       
            //关闭连接
            //page.Response.Flush();
            //page.Response.Clear();
            //page.Response.End();

posted @ 2016-08-22 09:35  AndSir  阅读(241)  评论(0编辑  收藏  举报
http://www.andsir.cn