web config 配置如下:
<add key="ewnhUrl" value="192.168.0.1" />
读取文件并修改
XmlDocument xml = new XmlDocument();
//路径 var ConfigPathew = rootPath + "\dddl\Configs\system.config"; xml.Load(ConfigPathew); XmlNodeList nodesew = xml.GetElementsByTagName("add"); for (int i = 0; i < nodesew.Count; i++) { XmlAttribute attew = nodesew[i].Attributes["value"]; if (attew != null) { if (nodesew[i].Attributes[0].Value == "ewnhUrl") { attew = nodesew[i].Attributes["value"];
//要写入的文本 attew.Value = ExtranetIp.Text + ":" + port; break; } } } xml.Save(ConfigPathew);
//为当前文件夹赋予everyone权限
string rootPath = Directory.GetCurrentDirectory();
DirectorySecurity fsec = new DirectorySecurity();
fsec.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
System.IO.Directory.SetAccessControl(rootPath, fsec);