asp.net将textbox中的内容存储成txt文件
1个回答
展开全部
protected void Button1_Click(object sender, EventArgs e)
{
string Path = @"D:\str.txt";
string str = TextBox1.Text;
WriteFile(Path,str );
}
public static void WriteFile(string Path,string str)
{
if (!System.IO.File.Exists(Path))
{
System.IO.FileStream f = System.IO.File.Create(Path);
f.Close();
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(Path, true, System.Text.Encoding.GetEncoding("gb2312"));
f2.WriteLine(str);
f2.Flush();
f2.Close();
f2.Dispose();
}
{
string Path = @"D:\str.txt";
string str = TextBox1.Text;
WriteFile(Path,str );
}
public static void WriteFile(string Path,string str)
{
if (!System.IO.File.Exists(Path))
{
System.IO.FileStream f = System.IO.File.Create(Path);
f.Close();
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(Path, true, System.Text.Encoding.GetEncoding("gb2312"));
f2.WriteLine(str);
f2.Flush();
f2.Close();
f2.Dispose();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询