日期:2014-05-18 浏览次数:23380 次
public static void PrintToClient(string strFileContent, string strFileName, string extendName)
    {
        /*过滤掉windows下文件名称中的非法字符*/
        Regex reg = new Regex(@"[\\,/,:,\*,\?,<,>,\|]{1,}|" + "\"{1,}");
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "GB2312";  //设置了类型为中文防止乱码的出现 
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlPathEncode(reg.Replace(strFileName, "") + extendName));
        HttpContext.Current.Response.ContentType = "application/ms-word;charset=GB2312";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文
        HttpContext.Current.Response.Write(strFileContent);
        HttpContext.Current.Response.End();
    }