/// <summary> /// プロパティを保存する処理 /// </summary> private void SaveProperties() { try { FileInfo fi = new System.IO.FileInfo(GetLocalConfigFilePath()); if (fi.Exists != true) { if (fi.Directory.Exists != true) { fi.Directory.Create(); } } ConfigXmlDocument cdoc = new ConfigXmlDocument(); var cfg = cdoc.CreateElement("configuration"); var apps = cdoc.CreateElement("settings"); Func <string, string, bool> addItem = (key, val) => { var node = cdoc.CreateElement("add"); var attrK = cdoc.CreateAttribute("key"); attrK.InnerText = key; var attrV = cdoc.CreateAttribute("value"); attrV.InnerText = string.IsNullOrWhiteSpace(val) ? string.Empty : val; node.Attributes.Append(attrK); node.Attributes.Append(attrV); apps.AppendChild(node); return(true); }; addItem("LoginCheck", this.ライセンス情報記憶.ToString()); addItem("TextUr", Utility.Encrypt(this.ユーザーID)); addItem("TextLr", Utility.Encrypt(this.パスワード)); cdoc.AppendChild(cfg); cfg.AppendChild(apps); cdoc.Save(fi.FullName); } catch (Exception) { } finally { } }
public void SetAppSetting(string name, string value) { // Ensure there's an <appSettings> node inside <configuration> // If not, create it. XmlNode settingsNode = config.SelectSingleNode("configuration/appSettings"); if (settingsNode == null) { settingsNode = config.CreateNode(XmlNodeType.Element, "appSettings", ""); config.SelectSingleNode("configuration").AppendChild(settingsNode); } XmlAttribute key = config.CreateAttribute("key"); key.Value = name; XmlAttribute val = config.CreateAttribute("value"); val.Value = value; bool found = false; foreach (XmlNode n in settingsNode.ChildNodes) { if (n.Name == "add" && n.Attributes.GetNamedItem("key").Value == name) { n.Attributes.SetNamedItem(key); n.Attributes.SetNamedItem(val); found = true; break; } } if (!found) { XmlNode itemNode = config.CreateNode(XmlNodeType.Element, "add", ""); settingsNode.AppendChild(itemNode); itemNode.Attributes.SetNamedItem(key); itemNode.Attributes.SetNamedItem(val); } }