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);
}