【问题标题】:How can I get path of user.config from another assambly?如何从另一个程序集中获取 user.config 的路径?
【发布时间】:2013-03-26 15:30:13
【问题描述】:

我希望我的解决方案中的所有程序集只有一个配置文件。那么从其他程序集获取user.config 路径的最佳方法是什么?

【问题讨论】:

  • 你可以add a link到你想使用的配置文件。
  • 已经这样做了,但这会在运行时在不同的文件夹中生成一个单独的 user.config。
  • 啊,我以为您的意思是在构建时只需要一个 user.config 文件。我没有意识到您在运行时也想要一个配置文件。那么是的,你必须像下面大卫建议的那样做。

标签: c# .net configuration properties.settings user-config


【解决方案1】:

user.config 只不过是一个 xml 文件。然后你可以用 XmlDocument 来阅读它。

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;
}

【讨论】:

  • 那么我该如何获取 user.config 的正确位置呢?
  • 不知道user.config的位置?
  • 我怎么知道,因为它类似于:C:\Users\%username%\AppData\Local\%appname%\%appname%.exe_Url_0s1u3ca1jts0vu5qozcghkp3j4rzk3l2\%version%\?
  • 所以您可以将您的问题细化为:如何获取 user.config 的路径。
  • 嗨@christophrus。您找到问题的答案了吗?我也在尝试从不同的程序集中检索 user.config 的路径。谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-04
  • 2011-03-21
  • 1970-01-01
  • 2023-03-31
相关资源
最近更新 更多