If you want to convert a custom object [Product] to a string by using the XmlSerializer class, you can use the StringWriter class like:

           StringBuilder result = new StringBuilder(string.Empty);

           // Get the product from filesystem
           Product product = Load();

           // Convert object to string by using XmlSerializer
           using (StringWriter writer = new StringWriter(result))
           {
               XmlSerializer xs = new XmlSerializer(typeof(Product));
               xs.Serialize(writer, product);
           }

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.