Hi all,I have written an application that makes use of the DisplayLayouts' SaveAsXml() and LoadFromXml() functions.Everything works fine until I bind a DataTable (manually constructed) that has column names containing special characters like äöü etc.The LoadFromXml() call fails giving a System.Xml.XmlException: "Invalid character in the given encoding. Line xyz, position xyz."
Is there a way to deal with such column names or anything I can do to make the function work with such DisplayLayouts?Renaming the columns unfortunately isn't an option.
thanks in advance and have a great dayAndy
Hello Andy,
Could you please let me know of your exact version so I can test that in a sample, I am not able to reproduce it right now with 11.2.2050 and 12.1.2008.
Hi Boris,thank you for your quick response, it is very much appreciated.
We are using 11.2.20112.1010, the unsigned, version free assemblies.
Here is a copy of the calls:
using (MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(_displayLayoutXml))) { try { grdResults.DisplayLayout.LoadFromXml(ms); } catch (Exception ex) { Debug.Print(ex.ToString()); } }
using (MemoryStream ms = new MemoryStream()) { grdResults.DisplayLayout.SaveAsXml(ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { gridLayoutXml = sr.ReadToEnd(); } } cheersAndy
using (MemoryStream ms = new MemoryStream()) { grdResults.DisplayLayout.SaveAsXml(ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { gridLayoutXml = sr.ReadToEnd(); } }
cheersAndy
I indeed will research this further and for now am attaching a video from the execution of this sample(without changing any assemblies or something else).
Please take a look, I might be missing something, hope you could guide me if I am.
Hi Boris,after carefully investigating the video there was one thing that made me look closer.Actually everything you did was exactly what I did, but while comparing the outputs I found a slight difference. I had a decoder fallback operation in my output, you didn't.
So I changedEncoding.Default.GetBytes(displayLayoutAsString)
toEncoding.UTF32.GetBytes(displayLayoutAsString)
That seems to do the trick...
I will check with my main application but I am optimistic that this will fix the problem.
I am deeply sorry for troubling you with this problem, but I appreciated you help very much.That again was a perfect sample for great support! Keep it up :)
So thank you very much Boris and have a great weekend,best regardsAndy
Hello,
Thank you for your feedback, please let me know if you have any question or if something comes up.
Hi,
Using an Encoder to convert the stream into a string is a really bad idea. The whole point of an Encoder is to manipulate the stream and coerce it into a string of a particular encoding type. Modifying the stream in this way is basically just asking for it to be damaged.
If you want to convert the stream into a string, a better way to do it would be to use the StreamReader class - and then use a StreamWriter to get it back into a stream.
There's a similar discussion thread where I posted some sample code here:
Convert String to Stream correctly for DisplayLayout.Load() - Infragistics Community
Hi Mike,
I hope you are doing good.
Thanks a lot for this suggestion... it totally makes sense.I'll stick to this approach :)
cheers and thanks for this suggestionAndy