如何使用c#更新XML中连接字符串中的密码或其他属性。
$array = @("/website","//windows_service","/console_app","//windows","///IIS","test")
$arraysplit = $array.split(',');
Foreach ($string in $arraysplit)
{
if ($string.StartsWith("//"))
{
Write-Host "$string has two slash."
}
elseif($string.StartsWith("/"))
{
Write-Host "$string has one slashes."
}
else
{
#I want to exit only when below conditions meet
#1. if string doesnot have any slash or
#2. if string has more than two slashes
Write-Host "$string has more number of slashes or it doesnot have any slash. Exiting"
Exit -1
}
}
它可以是任何xml文件而不是来自同一应用程序的配置。 请帮忙。
答案 0 :(得分:0)
您仍可以更新xml:
使用此参考:
using System.IO;
使用此代码:
var XMLpath = "c:\test.xml"; //<< your xml here
if (!File.Exists(XMLpath))
{
using (StreamWriter XmlWrite = new StreamWriter(XMLpath, false))
{
string[] x = {@"<?xml version=""1.0""?>",
@"<configuration>",
@"<connectionStrings>",
@"<add name=""abcConnection"" connectionString=""server=10.10.12.12;database=Test1;uid=myUID;password=hello;timeout=20;""providerName=""System.Data.SqlClient"" />""",
@"<add name=""123Connection"" connectionString=""server=10.10.23.45;database=test2;uid=MyUSI;password=hello;"" providerName=""System.Data.SqlClient"" />",
@"</connectionStrings>",
@"</configuration>}";
foreach (string s in x)
{
XmlWrite.WriteLine(s);
}
}
}