zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    521.最长特殊序列 I
    520.检查大写字母
    459.重复的子字符串
    Java 读取 .properties 文件的几种方式
    Idea 使用教程
    db2 with用法
    DB2 alter 新增/删除/修改列
    Bootstrap treegrid 实现树形表格结构
    Mysql 递归查询
    navicat for mysql 下载安装教程
  • 原文地址:https://www.cnblogs.com/walleyekneel/p/2097244.html
Copyright © 2011-2022 走看看