[RESOLVED] [2.0] Small problem converting XML linebreaks into textboxes
Problem:
I'm saving the contents of a multiline textbox to an XML file but when I try to read that XML file it's inserting the actual character for a linebreak rather than creating a line break (it shows a square).
If I open the XML file in notepad it's showing the true line break like it should.
How do I fix this so my textboxes also show the true line break?
Re: [2.0] Small problem converting XML linebreaks into textboxes
Do you have the "Multilines" property enabled for your text-boxes?
Re: [2.0] Small problem converting XML linebreaks into textboxes
Quote:
I'm saving the contents of a multiline textbox
Yes. :D
Re: [2.0] Small problem converting XML linebreaks into textboxes
Anyone have a clue why this would happen? I'm using standard serialization on the XML file. I google'd/MSDN'd everything I could think of and no luck.
The contents of the XML tag are being stored into string variables before they are put in the textbox as well.
Re: [2.0] Small problem converting XML linebreaks into textboxes
I don't know about a real solution
But you can go for a work-around:
"when you read the string from the XML file, replace all of the unknown char occurrences with line breaks"
Re: [2.0] Small problem converting XML linebreaks into textboxes
Tried that before posting. :(
It's on drugs. The square is actually a carriage return according to ultra edit's "character property" feature (unless ultraedit is converting the unknown char to a valid CR automatically). Character #13.
Re: [2.0] Small problem converting XML linebreaks into textboxes
Are you storing it as CDATA in the XML file?
Re: [2.0] Small problem converting XML linebreaks into textboxes
Nope, here's the code I'm using:
Reading the XML file:
Code:
public Settings Load()
{
Settings settings = new Settings();
if (File.Exists(SettingsPath))
{
try
{
using (FileStream fs = new FileStream(SettingsPath, FileMode.Open))
{
XmlSerializer xs = new XmlSerializer(typeof(Settings));
settings = (Settings)xs.Deserialize(fs);
fs.Close();
}
}
catch (Exception e)
{
{
if (MessageBox.Show("Error:\r\n" + e.Message, "Error reading settings file", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
{
if (File.Exists(SettingsPath)) File.Delete(SettingsPath);
}
else
{
Environment.Exit(-1);
}
}
}
}
return settings;
}
Writing the XML file:
Code:
public void Save(Settings settings)
{
try
{
using (FileStream fs = new FileStream(SettingsPath, FileMode.Create))
{
XmlSerializer xs = new XmlSerializer(typeof(Settings));
xs.Serialize(fs, settings);
fs.Close();
}
}
catch (Exception e)
{
MessageBox.Show("Error:\r\n" + e.Message, "Error writing settings file", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK);
}
}
"Settings" is the name of my class that has this code. It's consisted of a few static structs which get stored in the XML file.
For displaying the values, I'm just using standard code.
On text change I'm saving the contents of the textbox to a string variable within the struct. Then when the program closes I'm saving all the contents of each struct to the XML file.
Re: [2.0] Small problem converting XML linebreaks into textboxes
Last bump. I've pretty much given up, and since it's on the 2nd page maybe someone else who had this problem didn't get a chance to see it.
Re: [2.0] Small problem converting XML linebreaks into textboxes
saving to xml i did this by changing \n to <br>. Retreive then put to textbox with mutiline replace <br> to \n
Just try
Popskie
Re: [2.0] Small problem converting XML linebreaks into textboxes
VB Code:
saving to xml i did this by changing \n to <br>. Retreive then put to textbox with mutiline replace <br> to \n
sorry i thought it is asp.net forums.
Re: [2.0] Small problem converting XML linebreaks into textboxes
Yep, seems the textbox control is a little picky with linebreak syntax.
I had to change \n into \r\n when I read the file. \n by itself didn't work (tried this originally, under the assumption the square was an unknown char).
Re: [RESOLVED] [2.0] Small problem converting XML linebreaks into textboxes
What control you used in displaying that text?