c# 属于自己封装的类库(静态页面生成三种方式、导出文件类)

源代码完全公开,欢迎大家灌水!部分代码如下

1.

            //Response.ContentType是输出流的 HTTP MIME 类型
            //Response.ContentType     --- word文件
            //application/vnd.ms-excel --- excel文件
            //更多格式请参考http://walleyekneel.iteye.com/blog/979524
            HttpContext.Current.Response.Charset = "utf-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");

            //attachment --- 作为附件下载
            //inline --- 在线打开
            //filename如过是中文,则可以用HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)
            //进行进行编码,以解决文件名乱码的问题
            filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.Close();

2.

        /// <summary>
        /// 根据远程地址生成静态网页
        /// </summary>
        /// <param name="path">远程地址路径如http://localhost:9953/WebSite1/Default3.aspx</param>
        /// <param name="templatename">生成静态文件的路径如a/1.html</param>
        public static void GetHtml(string remotepath, string templatepath)
        {

            WebRequest wr = WebRequest.Create(remotepath);
            WebResponse wrp = wr.GetResponse();

            StreamReader sr = new StreamReader(wrp.GetResponseStream(), Encoding.GetEncoding("gb2312"));
            string str = sr.ReadToEnd();
            sr.Close();
            StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(templatepath), false, Encoding.GetEncoding("gb2312"));
            sw.Write(str);
            sw.Flush();
            sw.Close();

        }

迟点补充:分页、通过ID带出表中其他值、数据库备份、还原

CommonLibrary.rar

posted @ 2011-07-04 11:28  walleyekneel  阅读(1249)  评论(8编辑  收藏  举报