Free Jobs

Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: How to create and read html file from html string in C# Programmetically

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share

User: manishav3388 Post Date: 22 Apr 2011 03:28

Some times we need to save a html string as htl file and again need to read that.
In this post we will discuss the same.

Main Content:

suppose below is the html string that we have and we will save it as .html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >


    <title>Untitled Page</title>



<div><b>Hello Again</b></div>



       string body = TextBoxHtml.Text.Replace("''", "''''");


       StreamWriter sw;

        sw = File.CreateText(System.Configuration.ConfigurationSettings.AppSettings["HTMLFilePath"] + NameHTML.Text.Replace("''", "''''") + ".html");




reading that file as string.

when you will send it in mail with body as html it will come as html output

            string HtmlFilePath = System.Configuration.ConfigurationSettings.AppSettings["HtmlFilePath"].ToString()

                                  + ds.Tables[0].Rows[0]["Html"].ToString();//This is file name in database

            WebRequest    LRequest = WebRequest.Create(HtmlFilePath);

            WebResponse   LResponse = NewsLetterRequest.GetResponse();

            StreamReader sr = new StreamReader(NewsLetterResponse.GetResponseStream());

            string  LHTML = sr.ReadToEnd();

            return  LHTML;

Thus we can read and write html file programmetically

About Writer:
hello,I am JAVA Developer from Noida.

Writer's Link: http://

Writer's Email:

Post Comment

Similar Articles Top ArticlesLatest Articles Other Articles by this Author Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)