Browse Source

MMO-20386:为美术工程提供一个保存文件失败会有提示的接口

lvlh 3 years ago
parent
commit
1dde8eb361
1 changed files with 25 additions and 0 deletions
  1. 25 0
      Common/CommonLang/Xml/XmlUtil.cs

+ 25 - 0
Common/CommonLang/Xml/XmlUtil.cs

@@ -124,6 +124,31 @@ namespace CommonLang.Xml
             return doc;
         }
 
+        static public bool SaveXML(String path, XmlDocument doc, out string errMessage)
+        {
+            try
+            {
+                using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
+                {
+                    XmlWriterSettings settings = new XmlWriterSettings();
+                    settings.Indent = true;
+                    settings.Encoding = Encoding.UTF8;
+                    using (XmlWriter xml = XmlWriter.Create(fs, settings))
+                    {
+                        doc.Save(xml);
+                        xml.Flush();
+                    }
+                    errMessage = null;
+                    fs.Close();
+                }
+            }
+            catch(Exception e)
+            {
+                errMessage = e.Message;
+            }
+            return errMessage == null;
+        }
+
         static public void SaveXML(Stream output, XmlDocument doc, bool autoDisposeStream)
         {
             try