what is wrong with this code?

J

juli jul

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

new_doc.Load(this.save_name);
foreach(XmlNode node in new_doc)
{
if(node.LocalName=="Result")
System.Console.WriteLine("Result");
}


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

Henk Verhoeven

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
 
F

Frank Eller

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

new_doc.Load(this.save_name);
foreach(XmlNode node in new_doc)
{
if(node.LocalName=="Result")
System.Console.WriteLine("Result");
}


I get an error ,while it's running-why?

Which error?

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

Regards,

Frank Eller
www.frankeller.de
 
J

juli jul

Hello,
Here is the error:
An unhandled exception of type 'System.NullReferenceException' 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.EventArgs e)
{

SaveFileDialog save_file=new SaveFileDialog();
save_file.ShowDialog();
this.save_name=save_file.FileName;
File.Copy(this.file_name,this.save_name,true);
XmlDocument new_doc=new XmlDocument();

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


}

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top