Mark
Mark

Reputation: 2760

How to Edit a File(Html) which is read by the StreamReader in c#

   string BODY = String.Empty; 
            string PageName = @"[C:\Users\User1\Desktop\SK\Resources\HTMLEmail\email.html]";  
            BODY = new StreamReader(PageName).ReadToEnd(); 

I am reading a HTml File in my C# code using the above code, what I want to do is add some text to the file and save it or I have to send the file to a method which sends a email with the file.

the code below is from the email.html I have to add the Email Address and password in the [Email Address] and [Password]. How can i add text to the read HTML. And how can I send it to the method after doing the edit. Thanks

 <tr>
       <td valign="top">
        <div mc:edit="std_content00">
            <h4>Welcome to Website</h4>
               <p>Your new login details are:</p>
               <p>Email address: [Email Address]</p>
               <p>Password: [Password]</p>

Sending the file to the webservices which sends the email along with the HTML page //call the webservice to send email to the newly created user ServiceClient service = new ServiceClient(); service.sendEmail(newuseremail, subject, BODY);

Upvotes: 0

Views: 2433

Answers (2)

Prashant Lakhlani
Prashant Lakhlani

Reputation: 5806

Once you get data in your string variable BODY, you can do BODY.Replace("[Email Address]","...").

Upvotes: 0

Marco
Marco

Reputation: 57573

Maybe it's not elegant nor the best solution, but it's fast and easy:

BODY = BODY
       .Replace("[Email Address]", email)
       .Replace("[Password]", password);
File.WriteAllText(newFilename, BODY);

Just a suggestion: to read BODY variable you'd better using

string BODY = File.ReadAllText(filename);

without the need to use streams (I think your email template is short...)

Upvotes: 2

Related Questions