troubleshooting Question

My c# applcation is gving build errors (An object reference is required for the non-static field, method, or property 'System.Xml.XmlDocument.Save(System.Xml.XmlWriter)')

Avatar of Loudninja
Loudninja asked on
Web Development.NET ProgrammingC#
2 Comments1 Solution626 ViewsLast Modified:
I am building a c# search application using visual studio 2008. I keep getting the following error:
An object reference is required for the non-static field, method, or property 'System.Xml.XmlDocument.Save(System.Xml.XmlWriter)'      

Below is the code
namespace Search_application
 
 
       
        private void saveButton_Click(object sender, EventArgs e)
        //The following code saves the XML document to a file
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "XML|.xml";
                sfd.FileName = "search.xml";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    FileStream fs = File.Open(sfd.FileName, FileMode.Append, FileAccess.Write);
                    XmlWriter writer = XmlWriter.Create(fs);
                    XmlDocument.Save(writer);
                    writer.Flush();
                    writer.Close();
                    fs.Flush();
                    fs.Close();
                }
            }
 
           
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 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 2 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