C#生成頁面靜態頁

/// <summary>
/// 生成靜態頁
/// </summary>
/// <param name="webpath"></param>
/// <param name="setpath"></param>
/// <returns></returns>
        public static string GetNetPageInfo(string webpath, string setpath)
        {

            try
            {

                WebClient myWebClient = new WebClient();

                myWebClient.Credentials = CredentialCache.DefaultCredentials;

                byte[] pageData = myWebClient.DownloadData(webpath);

                string pageHtml = Encoding.GetEncoding("utf-8").GetString(pageData);

                using (StreamWriter sw = new StreamWriter(setpath, false, Encoding.GetEncoding("gb2312")))//將獲取的內容寫入文本
                {

                    sw.Write(pageHtml);

                    sw.Dispose();

                }

                return "生成成功了! ";

            }

            catch (WebException ex)
            {

                return ex.Message;

            }
        }

發佈了42 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章