Reputation: 23
I am currently using CKEditor for my project to read and display the content of a html file.
However, instead of getting the content of the file, all I get is a string: < html > display in the editor.
But if I write the content directly to the page using response.write, then all the content of the file is displayed correctly.
this is the code snippet I used to read the file:
strPathToConvert = Server.MapPath("~/convert/");
object filetosave = strPathToConvert + "paper.htm";
StreamReader reader = new StreamReader(filetosave.ToString());
string content = "";
while ((content = reader.ReadLine()) != null)
{
if ((content == "") || (content == " "))
{ continue; }
CKEditor1.Text = content;
//Response.Write(content);
}
Can anybody help me to solve this problem? Many Thanks.
Upvotes: 1
Views: 1807
Reputation: 15797
You are in a while
loop and you are overwriting the contents of CKEditor every time since you use =
instead of +=
. Your loops should be:
StreamReader reader = new StreamReader(filetosave.ToString());
string content = "";
while ((content = reader.ReadLine()) != null)
{
if ((content == "") || (content == " "))
{ continue; }
CKEditor1.Text += content;
//Response.Write(content);
}
a better way would probably be to use
string content;
string line;
using (StreamReader reader = new StreamReader(filetosave.ToString())
{
while ((line= reader.ReadLine()) != null)
{
content += line;
}
}
CKEditor1.Text = content;
Upvotes: 2