I want to write a new XML file to disk but the following code gives an error.
static void Main(string[] args)
{
using (XmlWriter writer = XmlWriter.Create(@"C:\abc.xml"))
{
writer.WriteStartDocument();
writer.WriteStartElement("Employees");
writer.WriteEndElement();
writer.WriteEndDocument();
}
Console.ReadKey();
}
Can anybody help me with this?
Note: abc.xml does not already exist.
Obviously, you don’t have the right to access
C:. Choose a path you have access to or run the application with higher privileges.As a side note, for most scenarios, it’s not recommended to use
System.Xmlanymore, use LINQ to XML (System.Xml.Linq) instead: