I'm trying to open a xml file (ansi) and converting and saving it UTF-8.
Here is my code:
using System;
using System.IO;
using System.Text;
using System.Xml;
class Test
{
public static void Main()
{
string path = @"C:\test\test.xml";
string path_new = @"C:\test\test_new.xml";
try
{
XmlTextReader reader = new XmlTextReader(path);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UTF8Encoding(false);
using (var writer = XmlWriter.Create(path_new, settings))
{
reader.Save(writer);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
I'm getting an error 'System.Xml.XmlTextReader' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'System.Xml.XmlTextReader' could be found (are you missing a using directive or an assembly reference?)
What class am I missing here ? Is my code correct to do the job
EDIT:
Okay here another code that is giving me exception:
using System;
using System.IO;
using System.Text;
using System.Xml;
class Test
{
public static void Main()
{
string path = @"C:\project\rdsinfo.xml";
//string path_new = @"C:\project\rdsinfo_new.xml";
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
It's giving me an exception, invalid character in the given encoding.