C#生成单页静态页简单实例
本文实例讲述了C#生成单页静态页简单实现方法。分享给大家供大家参考。具体方法如下:
protectedvoidBtGroup_ServerClick(objectsender,EventArgse)
{
//产业群首页
stringtempGroupData=GetHttpData("http://www.XXXX.com/Test/index.aspx");
using(StreamWritersw=newStreamWriter(this.Request.PhysicalApplicationPath+"Group\\Index.html",false,System.Text.Encoding.GetEncoding("utf-8")))
{
sw.Write(tempGroupData);
sw.Flush();
}
}
publicstringGetHttpData(stringsUrl)
{
stringsRslt=null;
WebResponseoWebRps=null;
WebRequestoWebRqst=WebRequest.Create(sUrl);
oWebRqst.Timeout=50000;
try
{
oWebRps=oWebRqst.GetResponse();
}
finally
{
if(oWebRps!=null)
{
StreamReaderoStreamRd=newStreamReader(oWebRps.GetResponseStream(),System.Text.Encoding.GetEncoding("utf-8"));
sRslt=oStreamRd.ReadToEnd();
oStreamRd.Close();
oWebRps.Close();
}
}
returnsRslt;
}
希望本文所述对大家的C#程序设计有所帮助。