C#通过动态页面生成静态页面

来源:互联网 发布:淘宝如何制作详情页 编辑:程序博客网 时间:2024/05/21 22:21
 
    protected void Button1_Click(object sender, EventArgs e)
    
{
        
string lcUrl = "http://localhost:2344/Web/index.aspx";
        HttpWebRequest loHttp 
= (HttpWebRequest)WebRequest.Create(lcUrl);
        
//   ***   Set   properties   
        loHttp.Timeout = 10000;           //   10   secs   
    
//    loHttp.UserAgent = "Code   Sample   Web   Client";
        
//   ***   Retrieve   request   info   headers   
        HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
        Encoding enc 
= Encoding.GetEncoding("UTF-8");     //   Windows   default   Code   Page   
        StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc);
        
string lcHtml = loResponseStream.ReadToEnd();
        loWebResponse.Close();
        loResponseStream.Close();
        Response.Write(lcHtml);
        
//
        string path = "E:/lauka/NewSkyhu/Web/index.html";
        Create_html(path, lcHtml);
    }

    
private void Create_html(string allfilename, string htmlcode)
    
{
        FileStream CreateFile 
= new FileStream(allfilename, FileMode.OpenOrCreate);
        StreamWriter sw 
= new StreamWriter(CreateFile);
        sw.WriteLine(htmlcode);
//将拼好的Html代码写入页面中
        sw.Close();
    }
原创粉丝点击