I am wondering how I (in C# or VB .NET) can save an object to a file.
It needs to be compatible with any type of object. How can I do this? Let’s say I want to save an object of the type “MyPersonClass”.
I am using the .NET 4.0 framework, with WPF.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are looking for some control and compatibility with non .NET applications, consider using the SoapFormatter class (as outlined in John Boker’s MSDN link) or XML serialisation. The latter works slightly differently from standard serialisation.
You require the XmlSerializer class:
To serialize MyPersonClass using XML serialisation, you will need instances of XmlSerializer and StreamWriter (in System.IO):
I hope this is useful!