2015-06-30 53 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」