/// <summary> /// 读 /// </summary> /// <returns></returns> public string GetFolderPath() { FolderPath = ConfigurationSettings.AppSettings["folderPath"]; return FolderPath; }
/// <summary> /// 写 /// </summary> public void SetFolderPath(string folderPath) { if (String.IsNullOrEmpty(folderPath)) return; string fullPath =@"E:\aa\App.config"; if (!System.IO.File.Exists(fullPath)) { System.Windows.Forms.MessageBox.Show(fullPath + "文档不存在!"); return; } XmlDocument doc = new XmlDocument(); doc.Load(fullPath); XmlNodeList nodes = doc.GetElementsByTagName("add"); for (int i = 0; i < nodes.Count; i++) { XmlAttribute att = nodes[i].Attributes["key"]; if (att.Value == "folderPath") { nodes[i].Attributes["value"].Value = folderPath; break; } } doc.Save(fullPath); }