views:

20

answers:

3

I am new in c# , i just want to know is it possible to take whole html document in a single string. i even want to write it in another file.

Thanx in advance.

+1  A: 

Hi, its very simple, i have given 2 ways to implement this way 1

string path = "D:\\Read.html";
        string path1 = "D:\\write.html";


    StreamReader sr = new StreamReader(path);
    string html = sr.ReadToEnd();


    StreamWriter sw = new StreamWriter(path1);
    sw.WriteLine(html);

way 2

string path = "D:\\Read.html";
        string path1 = "D:\\write.html";

   html=ReadAllText(path);

    File.WriteAllText(path1, html);

But i ll prefer 2nd way cheers !!

Sangram
A: 

Sure no problem. string foo = file.ReadToEnd().

Wernight
+2  A: 
string html = File.ReadAllText(@"C:\myhtmlfiles\index.html");

File.WriteAllText(@"c:\someotherfile.html", html);
klausbyskov