String encoding = DetectEncodingXml();
if(encoding.IndexOf("UTF-8") > -1)
{
/* This is what we want. Run the code. */
}
else
{
/* Display error message. */
}
private string DetectEncodingXml()
{
try
{
XmlTextReader xreader = new XmlTextReader(openFileDialog.FileName);
xreader.Read();
Encoding xreaderEnc = xreader.Encoding;
string xreaderEncString = xreaderEnc.EncodingName;
return xreaderEncString;
}
catch(Exception ex)
{
return " Encoding could not be detected. ";
}
}
No comments:
Post a Comment