文件下载

来源:互联网 发布:c网络应用编程 第3版 编辑:程序博客网 时间:2024/05/16 09:04
                Response.Clear();
                Response.Buffer = true;
                //attachment表示作为附件下载,可改为online打开
                //filename为指定输出文件的名称,注意扩展名的一致   
                Response.AppendHeader("Content-Disposition","attachment;filename=user.txt");
                //Response.ContentType指定文件类型 可以为application/ms-excel
                /*
                    导出时会弹出对话框让你确认保存位置
                    你可以选择保存,也可以直接打开
                 */
               // Response.ContentType = "web/vnd.ms-word";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                //设置要显示的字和内容要保存的形式
                Response.Charset = "txt文档";
                this.EnableViewState = false;