asp.net 在页面中可以使用 ~ 获取web应用程序根目录,请问在cs 文件里 怎么获取呢?

2025-05-20 13:45:12
推荐回答(1个)
回答1:

string fullPath = "D:/sys/OutputFiles/";
if (!Directory.Exists("D:/sys/OutputFiles"))
{
Directory.CreateDirectory("D:/sys/OutputFiles");
}
if (!System.IO.File.Exists(fullPath))
{
System.IO.File.Create(fullPath).Close();
}
如果你知道根目录在哪里就用这种方法判断下,然后建立,直接找根目录我也不知道,我就是用这个方法把文件写道我的项目根目录下的