示例#1
0
 //, string filePath)
 public static string Serialize(List<Product> list)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(List<Product>), new XmlRootAttribute("Products"));
     //using (TextWriter writer = new StreamWriter(HttpContext.Current.Server.MapPath(filePath), false, System.Text.Encoding.UTF8))
     using (StringWriter writer = new StringWriterUtf8())
     {
         serializer.Serialize(writer, list);
         return writer.ToString();
     }
 }
示例#2
0
        public static string Serialize(List <Product> list)//, string filePath)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List <Product>), new XmlRootAttribute("Products"));

            //using (TextWriter writer = new StreamWriter(HttpContext.Current.Server.MapPath(filePath), false, System.Text.Encoding.UTF8))
            using (StringWriter writer = new StringWriterUtf8())
            {
                serializer.Serialize(writer, list);
                return(writer.ToString());
            }
        }