0
我正在编写一个使用WPF和C#的程序,该程序有一个“app.config”文件,用于存储多个服务器的名称和位置。该程序动态读取此配置文件,并在UI中显示它(等等)。编辑.config文件代码
我想包括一个前端的方式来添加新的服务器到配置文件,以便用户可以输入所需的服务器的属性,我的程序将其添加到配置文件。
我的配置文件本质上看起来是这样的:
<ServerConfig>
<Environment name="PROD">
<Server host="h1" share="s1" source="x1"/>
<Server host="h6" share="s1" source="x1"/>
<Server host="h7" share="s1" source="x1"/>
<Server host="h8" share="s1" source="x1"/>
<Server host="h155" share="s1" source="x1"/>
</Environment>
<Environment name="DEV">
<Server host="h2" share="s2" source="x2"/>
<Server host="h55" share="s1" source="x1"/>
<Server host="h115" share="s1" source="x1"/>
</Environment>
<Environment name="QA">
<Server host="h3" share="s3" source="x3"/>
<Server host="h46" share="s1" source="x1"/>
<Server host="h15" share="s1" source="x1"/>
<Server host="h2" share="s1" source="x1"/>
<Server host="h234" share="s1" source="x1"/>
<Server host="h6" share="s1" source="x1"/>
<Server host="h146" share="s1" source="x1"/>
</Environment>
</ServerConfig>
我希望用户能够输入主机,共享和来源,和环境,我需要找到一种方法来地方Xml代码行在适当的地方。
有没有一种方法可以搜索带有某个“名称”的标签(如搜索'QA'环境),然后添加该行? XmlWriter/XmlSerializer似乎只能从一个Xml文件的开头写入,而不能在写入之前对其进行梳理。
我很感激任何帮助。
你用-100点开始这个问题。你假设你可以写入app.config文件。你不能。并非没有获得UAC许可。它现在可以工作,在您部署应用程序后它将无法工作。 –
是的,你说得对。不过,我想我对单独的XML文件有同样的问题。 – Ryan