
[英]update value in file(web.config) present on another machine(shared folder/network) using C#
[英]Replace value in file(web.config) present on another machine(shared folder/network) using C#
我具有对另一台计算机上存在的文件的完全访问权限,并且在运行命令行中键入“ \\ username-txd \\ abcFolder \\ Configuration \\ MediaManagerConfig \\ Web.config”时,我可以访问上述文件,但是当我尝试执行以下操作时更新此特定文件中任何属性的值,不允许我更新。
代号:代号C#
当我将值传递给xmlDoc.Load(@filename)时;
文件名显示为我想要的传递值。 但是,一旦我继续调试代码,我就会看到文件路径附加了“ d:/”值。
然后文件名变成了文件名=“ D:\\ username-txd \\ abcFolder \\ Configuration \\ MediaManagerConfig \\ Web.config”
为什么附加D://。 它是指我的本地D盘吗????
带注释的行是我尝试过的一些选项
public void updateFileData()
{
private string filename="\\vinayb2txd\\atish\\Configuration\\MediaManagerConfig\\Web.config";
private string newElemetValue="qwerty";
//xmlDoc.Load("\\vinayb2-txd\\atish\\Configuration\\MediaManagerConfig\\Web.config");
//var path = System.Web.HttpContext.Current.Server.MapPath(@filename);
//string serverFilepath= Server.MapPath(@filename);
// FileStream xmlFile = new FileStream(filename, FileMode.Open,FileAccess.Read, FileShare.Read);
// xmlDoc.Load(xmlFile);
// string abc=new Uri(filename).LocalPath;
xmlDoc.Load(@filename);
XmlNodeList elementList = xmlDoc.GetElementsByTagName("add");
for (int i = 0; i < elementList.Count; i++)
{
if (elementList[i].Attributes["key"].Value == elementKey)
{
elementList[i].Attributes["value"].Value = newElementValue;
break;
}
xmlDoc.Save(filename);
}
}
在文件名字符串的开头需要四个斜杠才能将其解释为UNC路径。 否则,双斜杠将转义为单斜杠,这被解释为当前工作目录的根驱动器。
采用:
private string filename="\\\\vinayb2txd\\atish\\Configuration\\MediaManagerConfig\\Web.config";
要么
private string filename=@"\\vinayb2txd\atish\Configuration\MediaManagerConfig\Web.config";
当您将文件名定义为“ \\ vinayb2txd \\ atish \\ Configuration \\ MediaManagerConfig \\ Web.config”时。 它以它为相对路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.