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

来源:互联网 发布:finale 2014 mac 破解 编辑:程序博客网 时间:2024/05/17 03:43
第一步:
 在.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>