By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Proper way to store Form size in an XML config file? (Is this approach good?)

P: n/a
Hi,

I need to store the size of my form in a config file. I was saving
this in the registry, but I need it in a config file now.

I came up with the following code. The part I'm not so sure about is
where I call form.Height.ToString(). Should I be making use of some
better built-in serialization capability? When I was usind the
registry I was using TypeConverter to change things like Size,
Location, BackgroundColor, etc. to strings. Is this the right way to
do this in XML?

Thanks,
John

System.Xml.XmlDocument d = new System.Xml.XmlDocument();

d.AppendChild(d.CreateXmlDeclaration("1.0", null, null));

XmlElement eRoot = d.CreateElement("","root","");
d.AppendChild(eRoot);

XmlElement el = d.CreateElement(form.Name);
el.SetAttribute("Height", form.Height.ToString());
el.SetAttribute("Width", form.Width.ToString());
eRoot.AppendChild(el);

d.Save("bubba.xml");
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You have specific requirements on what attributes of the form you want to
save to the XML file. For this your approach is as good as any other.

You might get better performance if you use an XmlWriter.

-Naraen

-----
"John" <jo********@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
Hi,

I need to store the size of my form in a config file. I was saving
this in the registry, but I need it in a config file now.

I came up with the following code. The part I'm not so sure about is
where I call form.Height.ToString(). Should I be making use of some
better built-in serialization capability? When I was usind the
registry I was using TypeConverter to change things like Size,
Location, BackgroundColor, etc. to strings. Is this the right way to
do this in XML?

Thanks,
John

System.Xml.XmlDocument d = new System.Xml.XmlDocument();

d.AppendChild(d.CreateXmlDeclaration("1.0", null, null));

XmlElement eRoot = d.CreateElement("","root","");
d.AppendChild(eRoot);

XmlElement el = d.CreateElement(form.Name);
el.SetAttribute("Height", form.Height.ToString());
el.SetAttribute("Width", form.Width.ToString());
eRoot.AppendChild(el);

d.Save("bubba.xml");

Nov 12 '05 #2

P: n/a
Hi John,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to output int
values to the XML files. If there is any misunderstanding, please feel free
to let me know.

As far as I know, convert it to string is the best way to achieve this,
since Xml files are raw text files. Unless you need to encrypt the values,
just keep the height or width values as string.

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.