I would like to have only one configuration file for all assemblies that are in my solution. So what is the best way to get the path of user.config
from an other assembly?
Asked
Active
Viewed 240 times
1

christophrus
- 1,170
- 2
- 14
- 27
-
You could [add a link](http://blogs.msdn.com/b/jjameson/archive/2009/04/02/linked-files-in-visual-studio-solutions.aspx) to the config file you want to use. – ean5533 Mar 26 '13 at 15:34
-
Already did that, but this generates a seperate user.config in a different folder at runtime. – christophrus Mar 26 '13 at 15:44
-
Ah, I thought you meant that you only wanted one user.config file *at build time*. I didn't realize you wanted one config file at run time as well. Then yes, you'll have to do something like David suggested below. – ean5533 Mar 26 '13 at 15:46
1 Answers
0
user.config is nothing but a xml file. You can read it with XmlDocument then.
XmlDocument doc = new XmlDocument();
doc.LoadXml("user.config");
XmlElement element = doc.DocumentElement;
XmlAttributeCollection attr_coll = myElement.Attributes;
for (int i = 0; i < attr_coll.Count; i++)
{
string attr_name = attr_coll[i].Name;
}

David
- 15,894
- 22
- 55
- 66
-
-
-
How would I know since its something like: C:\Users\%username%\AppData\Local\%appname%\%appname%.exe_Url_0s1u3ca1jts0vu5qozcghkp3j4rzk3l2\%version%\ ? – christophrus Mar 26 '13 at 15:50
-
so you might refine your question as: how do I get the path of user.config. – David Mar 26 '13 at 15:52
-
Hi @christophrus . Have you found an answer to your question? I'm trying to retrieve the path to user.config from different assembly as well. Thank you! – Norbert Szenasi Jun 22 '20 at 14:17