MVC4 2010项目中未声明路径的文件保存在哪里



我使用file.Create方法创建了一个文件路径为"test.txt"的文件。

我已经设法使用电子邮件类和"test.txt"的文件路径将此文件通过电子邮件发送给自己

我想在我的项目文件夹中找到实际的文件,但即使搜索test.txt也找不到。

它是一个临时文件吗?它将保存到哪里?

我正在用以下代码创建文件:

public void createCSVFile()
{
    string fileLocation = "test";
    mFilePath = fileLocation+".txt";
    if (!File.Exists(mFilePath))
    File.Create(mFilePath).Close();
}

我认为以下内容将帮助您将文件映射到特定位置,以进一步帮助您:

Server.MapPath指定映射到物理目录的相对路径或虚拟路径。

Server.MapPath("."), Server.MapPath(null), Server.MapPath("") will return the physical directory of the file being executed
Server.MapPath("..") will return the parent directory
Server.MapPath("~") will return the physical path to the root of the application

举个例子,如果你有一个存储在C:\website磁盘上的网站,mapPath将返回以下信息:

Server.MapPath("..")将返回:"C:\Website"

Server.Mappath(".")将返回"C:\Website{controllerName}"

Server.MapPath("~")将返回:"C:\Website"

最新更新