txt文档在.net中的操作

来源:互联网 发布:九阴真经最新辅助软件 编辑:程序博客网 时间:2024/04/28 07:00

读取的方法帮在页面的标题
 public   void bingtitle()
        {
            string path =Server.MapPath("~//App_Data//title.Txt");   //路径
            System.IO.StreamReader reader = new System.IO.StreamReader(path, System.Text.Encoding.Default);
             string str= reader.ReadLine();
             this.Header.Title = str.ToString();
             reader.Close();
        }


//修改的方法
  protected void bto_Edit_Click(object sender, EventArgs e)
        {
            string title=txt_title.Text.ToString().Trim();
             string path = Server.MapPath("~//App_Data//title.Txt");
             System.IO.StreamReader reader = new System.IO.StreamReader(path, System.Text.Encoding.Default);
            string str = reader.ReadLine();
             reader.Close();
             string s = str.Replace(str, title);
             System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false, System.Text.Encoding.Default);
             sw.WriteLine(s);
             sw.Close();
             Response.Write("<script>alert('修改成功!')</script>");
         
        }

原创粉丝点击