{
System.IO.StringWriter sw;
HtmlTextWriter htmltw;
sw = new System.IO.StringWriter();
htmltw = new HtmlTextWriter(sw);
base.Render(htmltw);
htmltw.Close();
sw.Close();
String tempsource = sw.ToString();
//tempsource is the HTML code of the page, you can create HTML page with it to complete converting aspx to HTML.
}
private void saveURL(string url)
{
if (!string.IsNullOrEmpty(url))
{
string content = "";
System.Net.WebRequest webRequest = WebRequest.Create(url);
System.Net.WebResponse webResponse = webRequest.GetResponse();
System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
content = sr.ReadToEnd();
//save to file
StreamWriter sw = new StreamWriter(Server.MapPath("webcontent.txt"));
sw.Write(content);
sw.Flush();
//display it in this page
Response.Write(content);
}
}
You can call the method like: saveURL("http://forums.asp.net/t/1201527.aspx"); Please pay attention on the format of URL, "http://" is necessary. Without it, you will encounter the error "The format of the URI could not be determined. "
Also, you can retrieve the HTML responsed with cross-domain through this server agent.
2 comments:
Autocomplete Code is not working . I use Pagemethod instead of webmethod
Did you apply PageMethod in right way? BTW, PageMethod only can be worked in aspx page. Also, check the stipulation between server and client.
Post a Comment