Two methods
Method 1:
/** // <Summary>
/// Static page generation method
/// </Summary>
/// <Param name = "strPageUrl"> Generate source </param>
/// <Param name = "strFileName"> generated to </param>
Private bool MakePage (string strPageUrl, string strFileName)
{
String strDir, strFilePage;
StrDir = @ "/htm/MakePage/"; // The updated folder.
StrFilePage = Server. MapPath (strDir + strFileName );
StreamWriter sw = null;
// Obtain the static html of aspx
Try
{
If (! Directory. Exists (Server. MapPath (strDir )))
{
Directory. CreateDirectory (Server. MapPath (strDir ));
}
If (File. Exists (strFilePage ))
{
File. Delete (strFilePage );
}
Sw = new StreamWriter (strFilePage, false, System. Text. Encoding. GetEncoding ("GB2312 "));
Server. Execute (strPageUrl, sw );
}
Catch (Exception ex)
{
Msg. ShowMsg ("'" + strFileName + "' generation error:" + ex. Message );
Return false; // An error occurred while generating the code.
}
Finally
{
Sw. Flush ();
Sw. Close ();
Sw = null;
}
Return true;
}
Method 2:/** // <summary>
/// Static page generation method
/// </Summary>
/// <Param name = "strPageUrl"> Generate source </param>
/// <Param name = "strFileName"> generated to </param>
Private bool MakePage (string strPageUrl, string strFileName)
{
String strDir, strFilePage;
StrDir = @ "/htm/MakePage/"; // The updated folder.
StrFilePage = Server. MapPath (strDir + strFileName );
StreamWriter sw = null;
// Obtain the static html of aspx
Try
{
If (! Directory. Exists (Server. MapPath (strDir )))
{
Directory. CreateDirectory (Server. MapPath (strDir ));
}
If (File. Exists (strFilePage ))
{
File. Delete (strFilePage );
}
Sw = new StreamWriter (strFilePage, false, System. Text. Encoding. GetEncoding ("GB2312 "));
System. Net. WebRequest wReq = System. Net. WebRequest. Create (strPageUrl );
System. Net. WebResponse wResp = wReq. GetResponse ();
System. IO. Stream respStream = wResp. GetResponseStream ();
System. IO. StreamReader reader = new System. IO. StreamReader (respStream, System. Text. Encoding. GetEncoding ("gb2312 "));
Sw. Write (reader. ReadToEnd ());
}
Catch (Exception ex)
{
Msg. ShowMsg ("'" + strFileName + "' generation error:" + ex. Message );
Return false; // An error occurred while generating the code.
}
Finally
{
Sw. Flush ();
Sw. Close ();
Sw = null;
}
Return true;
}
Summary: method 1 can only use virtual paths (e.g., cannot use http://www.qq.com), and method 2 is opposite.