2012-08-10 123 views
-1

我試圖訪問我的項目中的文件。獲取項目內文件夾中文件的內容?

所以我會創建一個名爲Files的新文件夾,並在該文件夾中包含各種HTML文件。

無論如何,我可以訪問"Program/Files/file.html"或類似的文件。

+0

這裏需要更多的背景下...雖然我想你想要的東西,像'Directory.GetFiles()' – dtsg 2012-08-10 16:03:51

+0

你們是不是在你的程序訪問這些文件或者是你想將文件導入到你的項目? – docmanhattan 2012-08-10 16:05:29

+0

可能你可以解釋一下.. – Rajesh 2012-08-10 16:05:36

回答

3

你的意思是這樣的嗎?

using System.IO; 
... 

string folderPath = AppDomain.CurrentDomain.BaseDirectory; // or whatever folder you want to load.. 

foreach (string file in Directory.EnumerateFiles(folderPath, "*.html")) 
{ 
    string contents = File.ReadAllText(file); 
}