Results 1 to 4 of 4

Thread: [RESOLVED] Saving data in a xml file.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [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);
    
    }
    
    }
    steve

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Saving data in a xml file.

    Hi
    if your XML file on your PC is blank, by setting it to "Always Copy" will always send a blank file to the PDA whenever you run your application from VS

    Is that the problem?

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Saving data in a xml file.

    Hello Petevick,

    I think you will have to set it for 'Always copy' or 'copy if newer'. Otherwise the xml file will never been deployed on the PDA device.

    Many thanks,

    Steve
    steve

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Saving data in a xml file.

    Hi,
    but is that your problem - are you always replacing the XML file on the PDA with the one from your dev environment? If so, just set it to 'copy if newer'

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width