Dynamically generate a .html page in console application c#
I would like to create a .html page dynamically inside a directory using c# console application
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Anupam SinghRank #643 · 3.7K reputationPosted May 11, 2014, 11:44 PM EDT
you can simply use textwriter class
System.IO.TextWriter writehtmlFile = new StreamWriter("c:\\htmlfile.html");
writehtmlFile .WriteLine("your file text");
writehtmlFile .Flush();
writehtmlFile .Close();
Raghavendra Joshi30 reputationPosted May 11, 2014, 11:59 PM EDT
Thank you, actually i have a very long html data which i am supposed to write it inside a directory. Do i need to write it in a single line or is there any other method to write it. Will you please help me out in this.
Thanks & Regards,
Raghavendra
Anupam SinghRank #643 · 3.7K reputationPosted May 12, 2014, 12:24 AM EDT
Raghavendra Joshi30 reputationPosted May 12, 2014, 1:29 AM EDT
for example:-
->directory "x" consists "y.html" &
->directory "L" which will be inside directory "x" consists "m.html"
->"y.html" fetches data from database.
->"each link in "y.html" will be linked to "m.html"
I also have a question about fetching data from database table to a html file.
Anupam SinghRank #643 · 3.7K reputationPosted May 12, 2014, 2:13 AM EDT
And answer of your 2nd question is to use StringBuilder to build html page and then you can save it to directory..
like
DataTable dt=new DataTable();
fill data in dt
StringBulider sb=new StringBuilder();
sb.append("");
sb.append(dt.Rows[0][0]);
.
.
sb.append("");
then you can use
writehtmlFile .WriteLine(sb);
Raghavendra Joshi30 reputationPosted May 12, 2014, 5:21 AM EDT
Software DevelopmentIT - Training Institute
I want to write it in a table format using writehtmlFile.WriteLine i.e each row consits of 3 columns
ex :