求asp.net 文件创建并写下的方法
求asp.net 文件创建并写入的方法~
b/s的 需要一个方法带string的值 然后创建txt文件到网页根目录upfile文件夹,然后把string写入txt~~
------解决方案--------------------
------解决方案--------------------
随便写的 debug下
b/s的 需要一个方法带string的值 然后创建txt文件到网页根目录upfile文件夹,然后把string写入txt~~
c#
ASP.NET
String
------解决方案--------------------
FileStream myFs = new FileStream(txtFilePath, FileMode.Create);//txtFilePath为生成txt文件的路径
StreamWriter mySw = new StreamWriter(myFs);
mySw.WriteLine(writeStr);//writeStr为要写入的字符串
mySw.Close();
myFs.Close();
------解决方案--------------------
随便写的 debug下
/// <summary>
/// WirteFile
/// </summary>
/// <param name="str"></param>
private void WirteFile(string str)
{
if (!File.Exists(@"文件路径"))
{
try
{
//创建文件
FileStream fs = new FileStream(@"文件路径", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
//写入数据
sw.WriteLine(str);
sw.Close();
fs.Close();
//
}
catch()
{
}
}
else
{
}
}