Is there any way in C# to embed an XML file where I serialized some classes in my project, and then open it and deserialize my classes from it?
Share
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.
By embedding – do you mean embedding in the assembly? In visual studio, add the xml file to your project and set the Build Action in the Properties window to Embedded Resource.
Next, in your C# code, you can get a hold of the resource stream (described here – works the same way for all kinds of embedded content):
http://msdn.microsoft.com/en-us/library/aa287676(VS.71).aspx
When you have the stream, you can first initialize an XmlSerializer instance with the System.Type you want to deserialize, and then call .Deserialize(stream) (and cast it to the right type again).
HTH
–larsw