c#保存成txt文件

来源:百度知道 编辑:UC知道 时间:2024/05/30 04:51:42
在freetextbox里面输入的一些信息想以 DOC的文件形式保存在特定的文件加下面.当然要自动生成一个文件名和文件,再保存进去

文件后缀是无关紧要的。
看看c#中的流(System.IO)
StringBuilder sb = new StringBuilder();
sb.AppendLine("= = = = = =");
sb.AppendLine();
sb.AppendLine();

using (StreamWriter outfile = new StreamWriter(mydocpath +@"\AllTxtFile.txt"))
{
outfile.Write(sb.ToString());
}

File.WriteAllText(@"E:\MyFile1.Doc", freetextbox.Text);

StreamWriter sw = new StreamWriter(@"d:\txt.doc");
sw.Write(this.textBox1.Text);
sw.Flush();
sw.Close();