c# 键值数据保存XML文件

   /// <summary>
        /// 键值数据保存XML文件
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="data">数据</param>
        public static bool SaveXmlFile(string filePath, string fileName, SerializableDictionary<string, string> data)
        {
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (FileStream fileStream = new FileStream(filePath + fileName, FileMode.Create))
            {
                XmlSerializer xmlFormatter = new XmlSerializer(typeof(SerializableDictionary<string, string>));
                xmlFormatter.Serialize(fileStream, data);
            }

            if (File.Exists(filePath + fileName))
            {
                return true;
            }
            return false;
        }

 

posted @ 2018-09-28 20:35  紅人  阅读(986)  评论(0编辑  收藏  举报