2015-06-30 123 views
0

我用File.Create方法创建了一个简单的“test.txt”文件路径的文件。MVC4 2010项目中未保存路径的文件保存在哪里?

我设法使用电子邮件类和“test.txt”文件路径将此文件通过电子邮件发送给我自己。

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

它是一个临时文件,它将保存在哪里?

我创建用下面的代码文件:

public void createCSVFile() 
{ 
    string fileLocation = "test"; 
    mFilePath = fileLocation+".txt"; 

    if (!File.Exists(mFilePath)) 
    File.Create(mFilePath).Close(); 
} 
+0

向我们展示一些代码,特别是如何创建文件? – ramiramilu

+0

如果您需要帮助,请更加努力地设置代码的格式。 –

+0

是否要将文件保存到特定位置或者您只想知道文件保存的位置? –

回答

2

我认为下面将帮助您映射在特定位置的文件,以进一步帮助您:

使用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磁盘上存储的网站:\网站上的MapPath方法将返回以下:

使用Server.Mappath(“”)会返回: “C:\网站”

使用Server.Mappath( “ ”)将返回 “C:\网{} controllerName”

使用Server.Mappath(“ 〜”)将返回:“C:\ Website”