473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

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
2 1451
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BTHOMASinOHIO | last post by:
I am confussed on what the heck is going on ?! I have an HTML INPUT File Box on an Email Piece of an application. I know that File Size is set to 4MB in the WebConfig File and that is fine, but I...
5
by: Guadala Harry | last post by:
What are my options for *securely* storing/retrieving the ID and password used by an ASP.NET application for accessing a SQL Server (using SQL Server authentication)? Please note that this ID and...
10
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
21
by: Nick Craig-Wood | last post by:
Lance Gamet <lance@gamet.comwrote: I've found http://docs.python.org/lib/module-ConfigParser.html To be easy to use and built in. It makes human readable / editable ..ini - like files. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.