Tuesday, July 28, 2009

Create New HTML Page At Run Time

public void CreatePageHTMLRunTime()
{
try
{


WebRequest mywebReq;
WebResponse mywebResp;
StreamReader sr;
string strHTML;
StreamWriter sw;
string currentPageUrl = Request.Url.ToString();
mywebReq = WebRequest.Create(currentPageUrl);
mywebResp = mywebReq.GetResponse();
sr = new StreamReader(mywebResp.GetResponseStream());
strHTML = sr.ReadToEnd();
string replace = "";
string strw="Welcome to Our Website!";

string sView= strHTML.Replace(replace,strw);

sw = File.CreateText(Request.PhysicalApplicationPath + "/Html/" + "Html" + int.Parse(Request.QueryString["OrderId"].ToString()) + ".html");
sw.WriteLine(sView);
sw.Close();
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "message", "self.close();", true);
}
catch
{
}

}
public void Create()
{
string sPath=Request.PhysicalApplicationPath + "/Html/" + "Html" + int.Parse(Request.QueryString["OrderId"].ToString()) + ".html";
FileInfo fi = new FileInfo(sPath);
if (fi.Exists)
{
cmdCreate.Enabled = false;
cmdCreate.Text = "Page already created";
}

}

No comments:

Post a Comment