File Write

using System.IO;
using System.Text;

namespace WebApplication1
{
    public partial class WriteFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {}

        protected void btnWrite_Click(object sender, EventArgs e)
        {
            string FileName = "./FileText.txt";
            FileStream fs = new FileStream(Server.MapPath(FileName), FileMode.OpenOrCreate, FileAccess.ReadWrite);
            byte[] FileByle = new byte[Encoding.UTF8.GetByteCount(tbContent.Text)];
            FileByle = Encoding.UTF8.GetBytes(tbContent.Text);
            fs.Write(FileByle, 0, FileByle.Length);
            fs.Close();
            fs.Dispose();
            Response.Write("write file is ok");
        }
    }
}


發佈了39 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章