Search code examples
c#visual-studiosettingsuser-management

How to use Settings for Specific User


Using Settings in C# we can assign a Set of Settings like ,Name ,Location ,Size etc. using Visual Studio and chose at which Scope it should be (Application/User).

My Question is ,can i use a Set of Settings separately for each user . Like i would Save User's like User1,User2,User3 where every user have same Attributes like Name ,Surname , Department .

So using Settings is it possible to save Name ,Surname and Department for User1 than the same thing for User2 .

Or is it better to create an Object User with those Fields/Properties and Serialize/Deserialize into XML .

Note : Attributes in this question are just Examples .


Solution

    • Option 1 : As you've mentioned, you could serialize your objects like here (http://www.codeproject.com/KB/XML/xml_serializationasp.aspx)

      Note : That article is old, you probably don't want to use the ArrayList.

    • Option 2 (Recommended): You could use your own custom type with Application Settings : Custom type application settings in ASP.NET

      Referring to the linked question, you could do this:

      public class MyUser
      {
         public string Name { get; set; }
         public string Surname { get; set; }
         public int Age { get; set; }
      }
      public class UserCollection : Collection<MyUser>
      {
      }