예제 #1
0
        public static XMLSettings GetSettingsCTI()
        {
            XMLSettings   data       = null;
            XmlSerializer serializer = new XmlSerializer(typeof(XMLSettings));
            FileStream    fs         = null;

            try
            {
                string fileName = "XMLConfig.xml";
                fs   = new FileStream(fileName, FileMode.Open);
                data = (XMLSettings)serializer.Deserialize(fs);
                fs.Close();
            }
            catch
            {
                fs.Close();
                System.Windows.Forms.MessageBox.Show("读取 XMLConfig.xml 配置文件失败,将使用默认值。", "警告", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                data = new XMLSettings();
                try
                {
                    SaveSettingsCTI(data);
                }
                catch { }
            }

            return(data);
        }
예제 #2
0
        public static void SaveSettingsCTI(XMLSettings data)
        {
            string        fileName   = "XMLConfig.xml";
            XmlSerializer serializer = new XmlSerializer(typeof(XMLSettings));

            // serialize the object
            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                serializer.Serialize(fs, data);
                fs.Close();
            }
        }