您的位置:首页 > 编程语言 > C#

C# 创建文件并往文件里写内容

2008-01-30 10:34 190 查看

protected void btnCreate_Click(object sender, EventArgs e)




...{


string path = HttpContext.Current.Request.PhysicalPath;


string file = path.Substring(0,path.LastIndexOf("/")+1) + @"命令.bat";


if (File.Exists(file))




...{


StreamWriter sw = File.AppendText(file);


sw.WriteLine("net state");


sw.Close(); //关闭流


sw.Dispose(); //销假对象


}


else




...{


StreamWriter sw = File.CreateText(file);


sw.WriteLine("dir");


sw.Close();


sw.Dispose();


}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐