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

  • 相关阅读:
    LeetCode OJ:Divide Two Integers(两数相除)
    LeetCode OJ:Sqrt(x)(平方根)
    LeetCode OJ:Excel Sheet Column Number(表格列数)
    LeetCode OJ:Compare Version Numbers(比较版本字符串)
    LeetCode OJ:Valid Parentheses(有效括号)
    LeetCode OJ:Longest Common Prefix(最长公共前缀)
    LeetCode OJ:Linked List Cycle II(循环链表II)
    LeetCode OJ:Permutations II(排列II)
    LeetCode OJ:Permutations(排列)
    MongoDB复制二:复制集的管理
  • 原文地址:https://www.cnblogs.com/walleyekneel/p/2097244.html
Copyright © 2011-2022 走看看