我想使用在线编辑器直接编辑服务器上的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。
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。
解决方案 »
- Lucene.Net如何优先搜索精确匹配的数据
- treeview定位问题c#
- 散分:深入讨论IspostBack,viewstate,session以及request.querystring
- dll反编译
- C#操作iis,如果取得一个应用程序池的应用程序列表或者应用程序数
- 如何将数据库中的内容随着网页的点开加载到头文件meta的keyword中去
- 求一种验证方法
- 高手指点:怎么把str字符串转为byte[]形式?
- 网站上偶尔报出的System.IO.FileNotFoundException
- 倾情奉献:本人写的客户端控件验证,挑战Microsoft的验证控件
- gridview与membership问题!
- 一个无分页的datagrid删除最后一条记录时的问题,在线急待
StreamReader sr = new StreamReader(Server.MapPath("div.html"));htmltext=sr.ReadToEnd();
sr.close();
content.Text = htmltext.ToString ();
{
strConent = ""; StreamReader sr = new StreamReader(FilePath); while (sr.ReadLine()!= null)
{
strConent += sr.ReadLine().Replace(" ","").Replace("\r\n","<br>");
} sr.Close();
}
还有个问题,以下代码在编辑器中显示为
<!-- Inject Script Filtered -->
都是脚本,可能是编辑器的安全设置吧,这个怎么解决?
<!--
function adRotator() {};
adRotator.initialize=function(o)
{
// script by blueDestiny
strConent += sr.ReadLine().Replace(" ","").Replace("\r\n","<br>");
加上后面的Replace之后,try里会报错,提示“未将对象引用设置到对象的实例。 ”
去掉之后,倒是可以显示源代码,但自动去掉了
<HTML><HEAD>以及<SCRIPT LANGUAGE="JavaScript">部分
我来总结一下:
使用sr.ReadLine()一行行的读,在TextBox会丢失<SCRIPT LANGUAGE="JavaScript">
使用sr.ReadToEnd()就没有问题。
另外CuteEditor对代码有过滤功能,不可能像DW那样智能。
总算是解决了,谢谢楼上各位!