zoukankan      html  css  js  c++  java
  • ASP.NET生成静态页面

    /// <summary>
            /// 生成静态页面
            /// </summary>
            /// <param name="webUrl">url</param>
            /// <param name="savePath">保存本地的路径</param>
            /// <returns></returns>
            public static void AppendHTML(string webUrl, string savePath)
            {
                Dictionary<string, string> dict = new Dictionary<string, string>(1);
                dict.Add(webUrl, savePath);
                AppendHTML(dict);
            }
            public static void AppendHTML(Dictionary<string, string> dict)
            {
                WebClient client = new WebClient();
                client.Credentials = CredentialCache.DefaultCredentials;  //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
                HttpContext context = HttpContext.Current;
                foreach (KeyValuePair<string, string> pair in dict)
                {
                    string url = pair.Key.StartsWith("http://") ? pair.Key : "http://" + context.Request.ServerVariables["HTTP_HOST"] + pair.Key;
                    string path = pair.Value;
                    path = Path.GetDirectoryName(AppRuntime.MapPath(path));
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    byte[] buffer = client.DownloadData(url);
                    long length = buffer.LongLength;
                    if (length > int.MaxValue)
                    {
                        throw new IOException("FileTooLong2GB");
                    }
                    int count = (int)length;
                    using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
                    using (BinaryWriter writer = new BinaryWriter(stream, Encoding.Default))
                    {
                        writer.Write(buffer, 0, count);
                    }
                }
                client.Dispose();
            }
    

  • 相关阅读:
    UVa 531 Compromise
    UVa 10130 SuperSale
    UVa 624 CD
    2015年第一天有感
    Bootstrap3.0学习(一)
    IIS上.net注册
    11g Oracle导出表 默认不导出数据为空的表解决
    Oracle数据库密码重置、导入导出库命令
    每天进步一点--WCF学习笔记
    C#每天进步一点--异步编程模式
  • 原文地址:https://www.cnblogs.com/Googler/p/1913870.html
Copyright © 2011-2022 走看看