How do I load xml used in form1 in form2?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How do I load xml used in form1 in form2?

Threaded View

  1. #1
    Join Date
    Apr 2011
    Posts
    4

    Angry How do I load xml used in form1 in form2?

    the program that I am writing has a listbox that displays application names (read from an xml). when I click on an application name in the listbox it runs the application.

    by the way, I am using visual studio professional 2010 4.0

    What I want to add is this. I want to be able to drag and drop an application into the listbox, have a second form come up with text boxes for the user to enter the application name (as they want it to appear in the list) and the application path. After clicking "submit" on form2 it will write to the existing xml, close form2, and refresh the listbox in form1.

    I am able to get the form2 to come up as soon as an application icon is dropped in the listbox.
    Here are my issues:
    1. form2 won't load the xml. I get an error that states "the name w7_apps.xml does not exist in the current context" w7_apps.xml is obviously the name of my xml file.
    2. since I can't expect the user to always know the path, instead I'd like to have the path automatically added to the xml when the application icon is dropped in the listbox.


    any help is appreciated. Thanks! my code from form2 is below. let me know if you need more info. This is my first time posting in this forum.

    private void btnSubmit_Click(object sender, EventArgs e)
    {
    XmlDocument doc = new XmlDocument();
    doc.Load(w7_apps.xml); //this is where I get the error

    if (txtDesc.Text != null)
    {
    XmlNode descNode = doc.CreateNode(XmlNodeType.Element, "app_desc", "");
    descNode.InnerText = txtDesc.Text;
    doc.DocumentElement.AppendChild(descNode);
    }
    else
    {
    MessageBox.Show("You must enter a description",
    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    if (txtPath.Text != null)
    {
    XmlNode pathNode = doc.CreateNode(XmlNodeType.Element, "app_path", "");
    pathNode.InnerText = txtPath.Text;
    doc.DocumentElement.AppendChild(pathNode);
    }
    else
    {
    MessageBox.Show("You must enter a path" + "\n" +
    "Right click on application icon" + "\n" +
    "Click properties, then copy path and paste in textbox",
    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }
    Last edited by Bluzman; May 6th, 2011 at 07:26 PM.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center