コード例 #1
0
        public static UserSettingXml GetUserSetting()
        {
            try
            {
                string filepath = Path.Combine(PathUtil.GetFolderPath(), "userSettingsXml.xml");
                if (!File.Exists(filepath))
                {
                    var set = new UserSettingXml();
                    SetUserSetting(set);
                    return(set);
                }
                else
                {
                    var retrievedUsers = new UserSettingXml();
                    using (var fs2 = new FileStream(filepath, FileMode.Open))
                    {
                        var serializer = new XmlSerializer(retrievedUsers.GetType());
                        retrievedUsers = serializer.Deserialize(fs2) as UserSettingXml;
                    }

                    return(retrievedUsers);
                }
            }
            catch
            {
                return(new UserSettingXml());
            }
        }
コード例 #2
0
 public static bool SetUserSetting(UserSettingXml usersToStore)
 {
     try
     {
         string filepath = Path.Combine(PathUtil.GetFolderPath(), "userSettingsXml.xml");
         if (File.Exists(filepath))
         {
             File.Delete(filepath);
         }
         using (var fs = new FileStream(filepath, FileMode.OpenOrCreate))
         {
             var serializer = new XmlSerializer(usersToStore.GetType());
             serializer.Serialize(fs, usersToStore);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }