Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Ihave created Html file using C# code ,But i want to add the DIV tag to perticular created html file along with text in textbox within DIV tag,Please suggest me about this to add a Div tag autometically my code is...

XML
sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        sb.AppendLine("<head id=\"Head1\" runat=\"server\">");
        sb.AppendLine("<title></title>");
        sb.AppendLine("</head>");
        sb.AppendLine("<body>");
        sb.AppendLine("<form id=\"form2\" runat=\"server\">");
        sb.AppendLine("<div>");
        sb.AppendLine(""+TextMessage+"");
        sb.AppendLine("<div>");
        sb.AppendLine("</form>");
        sb.AppendLine("</body>");
        sb.AppendLine("</html>");

        String filename = String.Concat(ApplicationDate, ".html");

        if (!Directory.Exists(ApplicationDate))
        {
            Directory.CreateDirectory(Server.MapPath("../ChatFiles/" + ApplicationDate));
        }
        File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\" + ApplicationDate + @"\" + filename, sb.ToString());
Posted
Updated 4-Feb-14 22:35pm
v2

1 solution

try this


C#
string TextMessage = "some message";
                string ApplicationDate = DateTime.Now.ToString("dd_MMM_yyyy");
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                sb.AppendLine("<head id=\"Head1\" runat=\"server\" >");
                sb.AppendLine("<title></title>");
                sb.AppendLine("</head>");
                sb.AppendLine("<body>");
                sb.AppendLine("<form id=\"form2\" runat=\"server\">");
                sb.AppendLine("<div>");
                sb.AppendLine(TextMessage);
                sb.AppendLine("<div>");
                sb.AppendLine("</form>");
                sb.AppendLine("</body>");
                sb.AppendLine("</html>");

                String filename = String.Concat(ApplicationDate, ".html");
                string path = Server.MapPath("ChatFiles");
                path = path + "\\" +ApplicationDate;
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                File.WriteAllText(path + @"\" + filename, sb.ToString());
 
Share this answer
 
Comments
SVT02 5-Feb-14 4:54am    
Actually its run perfectly ,But i want add number of DIV tag when 'TextMessage' text going to change time to time,i.e. when 'TextMessage' takes another text then DIV should increases
Karthik_Mahalingam 5-Feb-14 5:05am    
u mean u need to append text ??
SVT02 5-Feb-14 5:08am    
Yes,But How can i append the text?
Karthik_Mahalingam 5-Feb-14 5:15am    
check this code..
Karthik_Mahalingam 5-Feb-14 5:15am    
try this


protected void Page_Load(object sender, EventArgs e)
{

Some("hi", DateTime.Now.ToString("dd_MMM_yyyy"));


}

public void Some(string TextMessage , string ApplicationDate)
{

StringBuilder sb = new StringBuilder();
sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
sb.AppendLine("<head id=\"Head1\" runat=\"server\" >");
sb.AppendLine("<title></title>");
sb.AppendLine("</head>");
sb.AppendLine("<body>");
sb.AppendLine("<form id=\"form2\" runat=\"server\">");
sb.AppendLine("<div>");
sb.AppendLine(TextMessage);
//sb.AppendLine("<div>");
//sb.AppendLine("</form>");
//sb.AppendLine("</body>");
//sb.AppendLine("</html>");

String filename = String.Concat(ApplicationDate, ".html");
string path = Server.MapPath("ChatFiles");
path = path + "\\" + ApplicationDate;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);

File.AppendAllText(path + @"\" + filename, sb.ToString());

}

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