tags:

views:

47

answers:

1

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?

+3  A: 

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

larsw