I Added textfile on my Application Folder where the application is also located.
I having a problem where to locate and read the content of the texfile regarding what location the users specify the applicati开发者_JS百科on to be installed.
Example:
CASE 1: If Application Installed on C
Get the path of: C:\Textfile.txt
CASE 2:If Application Installed on Program files
Get the path of C:\Program Files\Default Company Name\Textfile.Text
Thanks in Regards.
i am not sure if this is what you wanted
string StartPath = Application.StartupPath; //or what SilverbackNet suggested
string FileName = "YourFileName.txt"
Textreader tr = new StreamReader(StartPath+ "\\" + FileName);
Console.WriteLine(tr.ReadLine());
tr.Close();
System.Windows.Forms.Application.ExecutablePath
is pretty much the go-to for this particular situation, especially for loading libraries. Please look at System.Environment.GetFolderPath(SpecialFolder.*)
for storing data, however, or you'll probably run afowl of stricter permission problems at some point.
精彩评论