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();
            }
    

  • 相关阅读:
    ZooKeeper实践:(1)集群管理
    删除重复数据只保留一条
    查询sqlserver 大小写
    字段按位数自动加空格
    批量更新数据遍历数据
    测试端口号是否开通
    收缩数据库
    插入ID=-1 的数据
    查询重复语句,多表查询
    oracle数据查询时间
  • 原文地址:https://www.cnblogs.com/Googler/p/1913870.html
Copyright © 2011-2022 走看看