开发者

How to Read texfile etch.. from Application folder where Application is Installed?

开发者 https://www.devze.com 2023-02-02 18:54 出处:网络
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 a

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消