小弟是初学者,请高手帮忙,如何在网页显示已经写好的TXT文本文件?急!急!急!急!急! 小弟是想做动态网页,就是说我想让网页的主要内容是变化的,如何实现????????请高手帮忙!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 just a sample: if(System.IO.File.Exists("d:\\siptest.log")) { string tmp = System.IO.File.OpenText("d:\\siptest.log").ReadToEnd(); Response.Write(tmp); } public void SetDatums(string Path,string Value) { if(!File.Exists(Path)) { FileStream fs = System.IO.File.Create(Path); writer = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312")); writer.Write(Value); } } public string GetDatums(string Path) { if(File.Exists(Path)) { reader =new StreamReader(Path,System.Text.Encoding.GetEncoding("GB2312")); return reader.ReadToEnd(); } else { return String.Empty; } } 给你一个读取文本的函数/// <summary>/// 读取文本/// </summary>/// <param name="filePath">要读取的文件路径及名称</param>/// <returns>返回该文本的全部内容</returns>public string myReadText(string filePath){ StreamReader myr = new StreamReader(filePath,System.Text.Encoding.Default); string mystr = ""; mystr = myr.ReadToEnd(); myr.Close(); return(mystr);}/// <summary>/// 将无格式的文本处理成有格式的文本/// </summary>/// <param name="mystr">要处理的文本</param>/// <returns>返回带换行等格式的文本</returns>public string MyReplace(string mystr){ if(this.MyisNull(mystr)) { return(" "); } else { mystr = mystr.Replace("\n\r","<br>"); mystr = mystr.Replace("\r","<br>"); mystr = mystr.Replace("\t"," "); return(mystr); }}需要在页面显示的时候如下(大意)this.Response.Write(MyReplace(myReadText(this.Server.MapPath("你的文本文件名"))); 感动ing!!!!!!!谢谢大家!!!!!!十分感谢!!!!!! String result; //你要的替换的文本String tmp; //StringReader reader =new StringReader("../Mybook.txt")tmp =reader.ReadLine();result = tmp;while ( tmp <> ""){ result += "#" + tmp; reader.ReadLine(); } 十分感谢大家,小弟又有了新的问题,就是怎么控制读入的TXT文本文件的位置及格式?麻烦大家了!!!!! 謝謝樓上的諸位,學習ing!! 例如:CompareValidator验证控件! 就是怎么控制读入的TXT文本文件的位置及格式?----------------你最好在页面上放一个控件,然后用表格控制此控件的位置即可. 如何循环给查出来的值前面加“-”?代码贴出来了。 进来帮忙说一下。谢谢、在线等。 vs 2005 网站 转 vs2003工作量到问题 请教一个问题 伪静态问题 IIS发布问题 求一个DIV弹出的 代码 关于FileUpload控件的问题,急~~~求高手帮帮忙 哪里找javascrip里边的一些对象的详尽资料?,比如document,windows等对象 只剩20分了!我的IIS怎么不能浏览aspx文件? 文件上传问题!!! js在windows2003下为什么不能运行了,好烦哦 新手问题:这段代码有什么问题吗? RequiredFieldValidator验证控件的疑问!!!
{
string tmp = System.IO.File.OpenText("d:\\siptest.log").ReadToEnd();
Response.Write(tmp);
}
{
if(!File.Exists(Path))
{
FileStream fs = System.IO.File.Create(Path);
writer = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));
writer.Write(Value);
}
}
{
if(File.Exists(Path))
{
reader =new StreamReader(Path,System.Text.Encoding.GetEncoding("GB2312"));
return reader.ReadToEnd();
}
else
{
return String.Empty;
}
}
/// <summary>
/// 读取文本
/// </summary>
/// <param name="filePath">要读取的文件路径及名称</param>
/// <returns>返回该文本的全部内容</returns>
public string myReadText(string filePath)
{
StreamReader myr = new StreamReader(filePath,System.Text.Encoding.Default);
string mystr = "";
mystr = myr.ReadToEnd();
myr.Close();
return(mystr);
}/// <summary>
/// 将无格式的文本处理成有格式的文本
/// </summary>
/// <param name="mystr">要处理的文本</param>
/// <returns>返回带换行等格式的文本</returns>
public string MyReplace(string mystr)
{
if(this.MyisNull(mystr))
{
return(" ");
}
else
{
mystr = mystr.Replace("\n\r","<br>");
mystr = mystr.Replace("\r","<br>");
mystr = mystr.Replace("\t"," ");
return(mystr);
}
}
需要在页面显示的时候如下(大意)
this.Response.Write(MyReplace(myReadText(this.Server.MapPath("你的文本文件名")));
谢谢大家!!!!!!
十分感谢!!!!!!
String tmp; //
StringReader reader =new StringReader("../Mybook.txt")
tmp =reader.ReadLine();
result = tmp;
while ( tmp <> "")
{
result += "#" + tmp;
reader.ReadLine();
}
----------------
你最好在页面上放一个控件,然后用表格控制此控件的位置即可.