asp.net 文件操作

 

using System.IO;
using System.Text;

/// <summary>
    ///
生成文件
    /// </summary>
    /// <param name="fname">
文件名</param>
    /// <param name="ftext">
文件內容</param>

public void makeHtml1(string flname, string fname, string ftext)
    {
        string _FileDir = HttpContext.Current.Server.MapPath(flname+@"\");
        //string _FileDir = ;
        //
創建文件夾
        if (!Directory.Exists(@_FileDir))
        {
            Directory.CreateDirectory(@_FileDir);
        }
        Encoding code = Encoding.GetEncoding("Gb2312");
        //
創建文件
        string phyPath = _FileDir + fname;
      
        string OldString = "";
        OldString = OldString + ftext;
        System.IO.StreamWriter sw = new System.IO.StreamWriter(phyPath, false, code);
        sw.Write(ftext);
        sw.Flush();
        sw.Close();
        sw.Dispose();
        HttpContext.Current.Response.Write("
成功生成:" + fname);
    }
protected void Button1_Click(object sender, EventArgs e)
    {
        string fl = this.TextBox3.Text;//
文件夾
        string aa = this.TextBox1.Text;//
文件
        string ss = aa + ".html";
        string content = this.TextBox2.Text;//
內容

        makeHtml1(fl, ss, content);
}

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