Click here to Skip to main content
15,922,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I want to generate .html using .cs file can u guide or send snippets
Posted

XML
using (FileStream fs = new FileStream("test.htm", FileMode.Create))
{
    using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
    {
        w.WriteLine("<H1>Hello</H1>");
    }
}
 
Share this answer
 
try something like this.


C#
public void GenerateHTMLClass(string xmlfileaddress, string htmlfilenaddress)
        {
            List<string> id = new List<string>();
            List<string> name = new List<string>();
            List<string> type = new List<string>();
            List<string> value = new List<string>();
            string htmlstring = "";
            XmlTextReader reader = new XmlTextReader(xmlfileaddress);

            while (reader.Read())
            {
                switch (reader.Name)
                {
                    case "GUID":
                        id.Add(reader.ReadString());
                        break;
                    case "Title":
                        name.Add(reader.ReadString());
                        break;
                    case "Type":
                        type.Add(reader.ReadString());
                        break;
                }
            }
            int i=0;
            foreach (var item in id)
            {
                htmlstring += "<" + type[i] + " id=" + item + " value=" + name[i] + "/>" + name[i] + "</" + type[i] + ">";
                i++;
            }
            using (FileStream fs = new FileStream(htmlfilenaddress, FileMode.Create))
            {
                using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
                {
                    writer.Write(htmlstringbegin + htmlstring + htmlstringend);
                }
            }
        }
 
Share this answer
 
Comments
kingsa 1-Oct-13 5:49am    
Thanks with great reply and what can i make it as start up page in my application so how can i generate events from html to .cs file for replacing data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900