Reputation: 3053
Im new to .net c# programming and i need to read remote xml file into dataset and create crystal report with the dataset.
so far everything works fine except some Unicode characters showing incorrectly in crystal report viewer
so is this the correct way to load xml file which contains unicode?
string reportDataPath = "http://domain/test/data.xml";
DataSet reportData = new DataSet();
try
{
reportData.ReadXml(reportDataPath);
}
catch
{
}
to set source
report = new SampleReport();
report.SetDataSource(reportData);
in xml file encoding set like
<?xml version="1.0" encoding="UTF-8"?>
edit:-
this is the problem im talking about. this is with sinhala unicode font
text in xml file is showing below
crystal report viewer shows below text
Regards
Upvotes: 1
Views: 2468
Reputation: 2103
Typically I always try to be explicit with my encoding types so I would do it like this:
System.Data.DataSet reportData = new System.Data.DataSet();
System.Net.WebRequest request= System.Net.WebRequest.Create(reportDataPath);
using (System.Net.WebResponse response = (System.Net.HttpWebResponse)request.GetResponse()) {
using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
reportData.ReadXml(sr);
}
}
Just be aware that unicode can be encoded using different formats, UTF-8, UTF-16, etc. Mostly what you'll see is UTF-8. In .NET the encoding type Encoding.Unicode is UTF-16
Upvotes: 1