• 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

  • 相关阅读:
    阿里巴巴
    实用得 JS 代码
    C#获得当前插入数据的ID
    “职场五魅”助你成功
    SQL2005导入导出数据库方法集合
    VS05里checkboxlist用JS获取 value值
    sql 去除html标签函数
    百度新闻搜索结果页的采集
    把表中的某个字段格式如:2,3,4的数据分别插入到另一个表中
    jquery 定位元素并获取数据
  • 原文地址:https://www.cnblogs.com/walleyekneel/p/2097244.html
Copyright © 2020-2023  润新知