Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How I can to get the app.config path?, not myapplication.exe.config path, the .config file in the my project root.

Thanks.
Posted
Comments
Manfred Rudolf Bihy 15-Sep-13 16:23pm    
Your question needs more context. What exactly is it you are trying to do?
Ejrr1085 15-Sep-13 16:45pm    
I encrypt myapplication.exe.config with RijndaelManaged, but I need read the app.config content first and after encrypt myapplication.exe.config everytime that I run my project in Visual Studio. Myapplication.exe.config return to be like app.config content when I clean, compile the solution and VS create the .exe. I can't encrypt myapplication.exe.config the same time I read this file. I could encrypt myapplication.exe.config with other application after generate the .exe, but I don't know if it is the only way.

1 solution

You are talking about the config file which is, by the design of CLR, is intended to be in the same directory as the main executable module
of the entry assembly of your application, and it is the subject of the same very schema you described in your question.

Moreover, you don't need to know the location of these file, as it is not designed to be used directly by the application (but it can be used to configure some other paths your application can use, as this is one of the purposes of configuration).

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa374182%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/2tw134k3.aspx[^].

You can always find the configuration file, but I'm afraid it would be a misuse of the feature. To find its full path, you can do this:
C#
//C#:
string location = System.Reflection.Assembly.GetEntryAssembly().Location;
string configLocation = string.Format("{0}.config", location); // but why?


If you need something else, you should probably introduce your own config file, encrypted or not. In particular, it's very convenient to use Data Contract:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

—SA
 
Share this answer
 

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