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
Hello again Andy,
That is odd - I could not reproduce this behavior at all. I am using your code with the mentioned version(CLR 2.0). I am afraid there could me something else in the code which messes up things. I will be happy if you could wrap this behavior in a small sample for me. Please let me know if this would be possible.
Hi Boris,thank you very much for your efforts.Unfortunately I am unable to wrap this part of the application in a sample.But I attached the Xml file that is created by saving the layout as txt.
The problem occurs in line 97, character 20
I am not sure if this is relevant, but I store the result in a SQL database.
gridLayoutXml = sr.ReadToEnd();
so gridLayoutXml is written into a varchar(max) field using Entity Framework.
Let me know if you need further information, I'll be happy to provide what's necessary.
Thanks again,Andy
Thank you for the attachment. So if you are not able to wrap this part into a sample, I suggest that we work on my sample. Please take a look and make the necessary modifications in order to reproduce this behavior.
Hi Boris,thanks a lot for the sample.I modified it so it reproduces the problem.I now get exactly the same error as in my main application using the DataSet you created.
let me know if you have any questions and best regardscheersAndy
Thank you for the sample provided. I downloaded and ran it but I do not get any exception or error, or a failure of some kind. Could you describe what exactly is the problem here? When I click on the button and execute Test1() method, the application just continues to run as it is the moment before. I got a little confused about this issue here, so a few details would be needed.
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
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
Hello,
Thank you for your feedback, please let me know if you have any question or if something comes up.
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
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.