2011-01-05 26 views
0

我在應用程序所在的應用程序文件夾中添加了文本文件。如何從應用程序安裝的應用程序文件夾中讀取texfile etch ..

我有一個問題,在哪裏找到並閱讀texfile的內容,關於用戶指定要安裝的應用程序的位置。

實施例:

CASE 1:如果應用程序安裝在C

獲取的路徑:C:\ TextFile.txt的

CASE 2:如果應用程序安裝上的程序文件

獲取C:\ Program Files \ Default Company Name \ Textfile.Text的路徑

謝謝。

回答

0

我不知道如果這是你想要的東西

string StartPath = Application.StartupPath; //or what SilverbackNet suggested 
string FileName = "YourFileName.txt" 

Textreader tr = new StreamReader(StartPath+ "\\" + FileName); 

Console.WriteLine(tr.ReadLine()); 

tr.Close(); 
0

System.Windows.Forms.Application.ExecutablePath對於這種特殊情況非常適合,特別是對於加載庫。但是,請注意System.Environment.GetFolderPath(SpecialFolder.*)用於存儲數據,否則您可能會在某些時候出現更嚴格的權限問題。

相關問題