小二哥's blog

----zhangzs8896(小二)

导航

在.net中访问硬盘中的.text文件,并用于滚动显示

Posted on 2004-10-15 16:36  小二哥  阅读(418)  评论(0编辑  收藏  举报
测试环境win2003+Vs.net  2003 (WebForm下)

第一步:
 在.cs文件中加一个引用:using System.IO;
  public string strNews;
  private void Page_Load(object sender, System.EventArgs e)
  {
   //读取new.text文件,并把内容给strNews用与滚动显示
   FileStream fs = new FileStream("c:\\通知.txt", FileMode.Open);
   byte[] bytes = new byte[(int)fs.Length];
   fs.Read(bytes, 0, bytes.Length);
   fs.Close();
   strNews = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);
   strNews=strNews.Replace("\r","<br>");
   strNews=strNews.Replace("\0","&nbsp;&nbsp;");
   strNews=strNews.Replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;");
   strNews=strNews.Replace(" ","&nbsp;&nbsp;");
  }

第二步:在html下<body>区域加一个MARQUEE :
<MARQUEE onmouseover=this.stop() style="BORDER-RIGHT: dimgray thin; BORDER-TOP: dimgray thin solid; Z-INDEX: 101; LEFT: 8px; BORDER-LEFT: dimgray thin; WIDTH: 780px; COLOR: green; BORDER-BOTTOM: dimgray thin solid; POSITION: absolute; TOP: 358px; HEIGHT: 57px; TEXT-DECORATION: none" onmouseout=this.start() scrollAmount=3 scrollDelay=80 direction=up><%=strNews%></MARQUEE>