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();
}
}
本文介绍如何在ASP.NET应用程序中根据当前请求路径创建批处理文件,并根据不同情况追加或写入命令。如果批处理文件已存在,则向其中追加net state命令;若不存在,则创建新文件并写入dir命令。





