|
-
Mar 6th, 2008, 04:33 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Saving data in a xml file.
Hello,
Using VS 2008 CF 3.5 WM 5.0
I need to save some data. I tried using the resource file. I could read the data, but not sure how to save it. I think that this might be read only.
However, so I tried using a xml file and set the property "Copy to output directory" to "Always Copy".
I have used a ds to read and write the xml file. It writes the data ok, and I have checked this by browsing the xml file on the PDA itself. However, when i re-start the application it always displays blank data.
I am wondering what the problem is?
Second question what is the VS 2008 method of doing this?
Many thanks for any advice,
Steve
Code:
Code Snippet//Load server options from the resource file.
//Default options to be loaded on startup.
private void LoadServerOptions()
{
//Resources.resx is READ-ONLY
//this.txtSIP_Proxy.Text = GUI_SIP_Client.Properties.Resources.SIP_Proxy;
//this.txtDNS_Server.Text = GUI_SIP_Client.Properties.Resources.DNS_Server;
//this.txtSTUN_Domain.Text = GUI_SIP_Client.Properties.Resources.STUN_Domain;
//this.txtSTUN_Server.Text = GUI_SIP_Client.Properties.Resources.STUN_Server;
try
{
//Find path of executing assembly where XML file is located
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
//Read the xml file into the DS so that the values can be read.
ds.ReadXml(System.IO.Path.Combine(path, "ServerOptions.xml"));
this.txtSIP_Proxy.Text = ds.Tables[0].Rows[0]["SIPServer"].ToString();
this.txtDNS_Server.Text = ds.Tables[0].Rows[0]["DNSServer"].ToString();
this.txtSTUN_Domain.Text = ds.Tables[0].Rows[0]["STUNDomain"].ToString();
this.txtSTUN_Server.Text = ds.Tables[0].Rows[0]["STUNServer"].ToString();
}
catch (System.IO.FileNotFoundException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//Save the current server settings in the resource file to be
//loaded the next time the application starts up.
private void btnSave_Click(object sender, EventArgs e)
{
try
{
//Write the contents of the server options to the xml file so that they can be saved.
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
ds.Tables[0].Rows[0]["SIPServer"]= this.txtSIP_Proxy.Text;
ds.Tables[0].Rows[0]["DNSServer"] = this.txtDNS_Server.Text;
ds.Tables[0].Rows[0]["STUNDomain"] = this.txtSTUN_Domain.Text;
ds.Tables[0].Rows[0]["STUNServer"] = this.txtSTUN_Server.Text;
//Write the new settings to the xml file.
ds.WriteXml(System.IO.Path.Combine(path, "ServerOptions.xml"));
}
catch (System.IO.FileNotFoundException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|