Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I always have doubt regarding how a path is formed whenever we run a windows app.

I have set a key like this in my app config

C#
<add key="LogFilePath" value="..\Log\" />



When i run this from my local machine, it provides the path from where the windows app is run.

But when i run the same project from TFS, and when i try to create a file inside the Log folder , instead of the project mapped path it gives an entirely different path.


Can anyone tell me why this happens?
Posted
Updated 25-Mar-14 19:25pm
v2

I suggest you determine the relevant run-time directory-paths in code:
C#
string appStartUp = Application.StartupPath;

string currentDirectory = Environment.CurrentDirectory;

string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Other useful information for global system paths can be found in the Environment.SpecialFolder Enumeration: [^].
 
Share this answer
 
v2
Comments
Arjun Menon U.K 26-Mar-14 2:36am    
what about this
string filePath = Directory.GetParent(Path.GetDirectoryName(Application.StartupPath)) + ConfigurationManager.AppSettings["LogFilePath"];
Note that a log file must not be placed in the program folder: a non-administrative user does not have sufficient priviledges to write it. Use e.g. %appdata%. That can be expanded by the Environment class.
XML
<add key="LogFilePath" value="%appdata%\YourCompany\Logs\xy.log" />

C#
string val = ConfigurationManager.AppSettings["LogFilePath"];
string path = System.Environment.ExpandEnvironmentVariables(val);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900