troubleshooting Question

C#; Merging XML files

Avatar of trevor1940
trevor1940 asked on
XML.NET ProgrammingC#
13 Comments1 Solution182 ViewsLast Modified:
I need to merge a bunch of xml files and save into 1 removing any duplicate entries
I'm getting errors in ConsoleApplication2 @ line         private history = new history();

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1519	Invalid token '=' in class, struct, or interface member declaration	ConsoleApplication2	d:\VB\Test\ConsoleApplication2\ConsoleApplication2\Program.cs	13	Active

any suggestions what the above is?

Unless there is a better way I was going to use sort on id to filter out duplicates with the newest file taking precedence over older

using System.IO;
using xml;

namespace ConsoleApplication2
    class Program
        private history = new history();

        static void Main(string[] args)
            string RootDir = @"C:\Users\user\AppData\Roaming\AppName\user";
            if (Directory.Exists(RootDir))
                var Files = Directory.EnumerateFiles(RootDir, "history.xml", SearchOption.AllDirectories);
                foreach (string File in Files)
                    this.history += xml.history.Load(File);



using System.Xml.Serialization;

namespace xml
    public class history
        List<post> post{ get; set; } = new List<post>();
        private static string xmlFile { get; set; }

        public static history Load(string xmlFile)

            XmlSerializer deserializer = new XmlSerializer(typeof(history));
            using (TextReader reader = new StreamReader(xmlFile))
                history history = (history)deserializer.Deserialize(reader);
                return history;

        public void Save(string xmlFile)
            XmlSerializer serializer = new XmlSerializer(typeof(history));
            using (TextWriter writer = new StreamWriter(xmlFile))
                serializer.Serialize(writer, this);


    public class post
        public string name { get; set; }
        public string url { get; set; }
        public int id { get; set; }
        public int number { get; set; }
        public int imageCount { get; set; }
        public int downloadedImagesCount { get; set; }
        public string finished { get; set; }

 XML file

    <name>My Collection </name>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros