我想使用在线编辑器直接编辑服务器上的HTML文件,代码如下:
        StringBuilder htmltext=new StringBuilder();
        try
        {
            StreamReader sr = new StreamReader(Server.MapPath("div.html")) ;
            String line;
            do
            {
                line = sr.ReadLine();
                htmltext.AppendLine(line);
            }
            while (line == null);
            sr.Close() ;
        }
        catch (Exception  E)
        {
            htmltext.Append(E.Message) ;
        }
        //Response.Write(htmltext.ToString() );
        content.Text = htmltext.ToString ();
但编辑器内始终为空,输出htmltext也为空,不知为何?
我使用的编辑器是CuteEditor。

解决方案 »

  1.   

    string htmltext;
    StreamReader sr = new StreamReader(Server.MapPath("div.html"));htmltext=sr.ReadToEnd();
    sr.close();
     
    content.Text = htmltext.ToString ();
      

  2.   

    public static void ReadFile(string FilePath,out string strConent)
        {
            strConent = "";        StreamReader sr = new StreamReader(FilePath);        while (sr.ReadLine()!= null)
            {
                strConent += sr.ReadLine().Replace(" ","").Replace("\r\n","<br>");
            }        sr.Close();
        }
      

  3.   

    谢谢zhangxiaopin(zxp)
    还有个问题,以下代码在编辑器中显示为
    &lt;!-- Inject Script Filtered --&gt; 
    都是脚本,可能是编辑器的安全设置吧,这个怎么解决?
    <!--
    function adRotator() {};
    adRotator.initialize=function(o)
    {
    // script by blueDestiny
      

  4.   

    TO:zhangxiaopin(zxp)
    strConent += sr.ReadLine().Replace(" ","").Replace("\r\n","<br>");
    加上后面的Replace之后,try里会报错,提示“未将对象引用设置到对象的实例。 ”
    去掉之后,倒是可以显示源代码,但自动去掉了
    <HTML><HEAD>以及<SCRIPT LANGUAGE="JavaScript">部分
      

  5.   

    终于使用TextBox控件搞定了!
    我来总结一下:
    使用sr.ReadLine()一行行的读,在TextBox会丢失<SCRIPT LANGUAGE="JavaScript">
    使用sr.ReadToEnd()就没有问题。
    另外CuteEditor对代码有过滤功能,不可能像DW那样智能。
    总算是解决了,谢谢楼上各位!