public static void Save() { string fileName = Path.Combine(configDirectory, propertyFileName); using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.WriteStartElement(propertyXmlRootNodeName); properties.WriteProperties(writer); writer.WriteEndElement(); } }
public static void Save() { using (MemoryStream ms = new MemoryStream()) { XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartElement(propertyXmlRootNodeName); properties.WriteProperties(writer); writer.WriteEndElement(); writer.Flush(); ms.Position = 0; string fileName = Path.Combine(configDirectory, propertyFileName); using (LockPropertyFile()) { using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { ms.WriteTo(fs); } } } }
public static void Save() { if (string.IsNullOrEmpty(configDirectory) || string.IsNullOrEmpty(propertyXmlRootNodeName)) { throw new InvalidOperationException("No file name was specified on service creation"); } using (MemoryStream ms = new MemoryStream()) { XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartElement(propertyXmlRootNodeName); properties.WriteProperties(writer); writer.WriteEndElement(); writer.Flush(); ms.Position = 0; string fileName = Path.Combine(configDirectory, propertyFileName); using (LockPropertyFile()) { using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { ms.WriteTo(fs); } } } }