what is wrong with this code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juli jul

    what is wrong with this code?

    File.Copy(this. file_name,this. save_name,true) ;
    XmlDocument new_doc=new XmlDocument();

    new_doc.Load(th is.save_name);
    foreach(XmlNode node in new_doc)
    {
    if(node.LocalNa me=="Result")
    System.Console. WriteLine("Resu lt");
    }


    I get an error ,while it's running-why?
    Thank you very much!


    *** Sent via Developersdex http://www.developersdex.com ***
  • Frank Eller

    #2
    Re: what is wrong with this code?

    Hi,[color=blue]
    > File.Copy(this. file_name,this. save_name,true) ;
    > XmlDocument new_doc=new XmlDocument();
    >
    > new_doc.Load(th is.save_name);
    > foreach(XmlNode node in new_doc)
    > {
    > if(node.LocalNa me=="Result")
    > System.Console. WriteLine("Resu lt");
    > }
    >
    >
    > I get an error ,while it's running-why?[/color]

    Which error?

    Remember: XmlDocument is a hierarchical thing, you need a recursive Method
    to loop through all the nodes in it.

    Regards,

    Frank Eller
    another blog about programming with all things related to .NET



    Comment

    • Henk Verhoeven

      #3
      Re: what is wrong with this code?

      Juli

      Could you post the error as well.

      One of the reasons might be that the "save_name" might be in use, try
      wrapping this code in a try catch to see exactly whet the errors are

      henk
      "juli jul" <juli8024@yahoo .com> wrote in message
      news:umpAVMrPFH A.1564@TK2MSFTN GP14.phx.gbl...[color=blue]
      > File.Copy(this. file_name,this. save_name,true) ;
      > XmlDocument new_doc=new XmlDocument();
      >
      > new_doc.Load(th is.save_name);
      > foreach(XmlNode node in new_doc)
      > {
      > if(node.LocalNa me=="Result")
      > System.Console. WriteLine("Resu lt");
      > }
      >
      >
      > I get an error ,while it's running-why?
      > Thank you very much!
      >
      >
      > *** Sent via Developersdex http://www.developersdex.com ***[/color]


      Comment

      • juli jul

        #4
        Re: what is wrong with this code?

        Hello,
        Here is the error:
        An unhandled exception of type 'System.NullRef erenceException ' occurred
        in Unknown Module.

        Additional information: Object reference not set to an instance of an
        object.
        And the code of the function :
        private void menuItem4_Click (object sender, System.EventArg s e)
        {

        SaveFileDialog save_file=new SaveFileDialog( );
        save_file.ShowD ialog();
        this.save_name= save_file.FileN ame;
        File.Copy(this. file_name,this. save_name,true) ;
        XmlDocument new_doc=new XmlDocument();

        try
        {
        new_doc.Load(th is.save_name);
        }
        catch(Exception ex)
        {
        MessageBox.Show (ex.ToString()) ;
        }


        }

        Please tell me what is wrong here?
        Thank you:)



        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        Working...