我目前正在使用CKEditor为我的项目读取和显示html文件的内容。
然而,我得到的只是一个字符串,而不是获取文件的内容:< html>在编辑器中显示。
但是如果我使用response.write直接将内容写入页面,那么文件的所有内容都会正确显示。
这是我用来读取文件的代码片段:
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);
}
有人可以帮我解决这个问题吗? 非常感谢。
答案 0 :(得分:1)
您处于while
循环中,并且每次使用=
而不是+=
时都会覆盖CKEditor的内容。你的循环应该是:
StreamReader reader = new StreamReader(filetosave.ToString());
string content = "";
while ((content = reader.ReadLine()) != null)
{
if ((content == "") || (content == " "))
{ continue; }
CKEditor1.Text += content;
//Response.Write(content);
}
更好的方法可能是使用
string content;
string line;
using (StreamReader reader = new StreamReader(filetosave.ToString())
{
while ((line= reader.ReadLine()) != null)
{
content += line;
}
}
CKEditor1.Text = content;