软件编程
位置:首页>> 软件编程>> C#编程>> C#生成单页静态页简单实例

C#生成单页静态页简单实例

作者:shichen2014  发布时间:2022-01-22 20:00:57 

标签:C#,生成,静态页

本文实例讲述了C#生成单页静态页简单实现方法。分享给大家供大家参考。具体方法如下:

protected void BtGroup_ServerClick(object sender, EventArgs e)
{
    //产业群首页
    string tempGroupData = GetHttpData("http://www.XXXX.com/Test/index.aspx");
    using (StreamWriter sw = new StreamWriter(this.Request.PhysicalApplicationPath + "Group\\Index.html", false, System.Text.Encoding.GetEncoding("utf-8")))
    {
 sw.Write(tempGroupData);
 sw.Flush();
    }
}
public string GetHttpData(string sUrl)
{
    string sRslt = null;
    WebResponse oWebRps = null;
    WebRequest oWebRqst = WebRequest.Create(sUrl);
    oWebRqst.Timeout = 50000;
    try
    {
 oWebRps = oWebRqst.GetResponse();
    }          
 
    finally
    {
 if (oWebRps != null)
 {
     StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
     sRslt = oStreamRd.ReadToEnd();
     oStreamRd.Close();
     oWebRps.Close();
 }
    }
    return sRslt;
}

希望本文所述对大家的C#程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com