I have the following xml file (snippet only:


<?xml version="1.0" encoding="utf-8" ?>
<course id="2555" title="Developing Microsoft .NET Applications for Windows (Visual C# .NET)" length="5 days" source="//www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx" href="http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx">http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx">
 <module id="1" title="Introducing Windows Forms" location="D:\Disk-C\Documents and Settings\orit_itzhar.ATRICA\My Documents\XML\csharp">
  <lesson id="1.1">
   <subject>Creating a Form</subject>
   <file>winforms.pdf</file>
  </lesson>
  <lesson id="1.2">
   <subject>Adding Controls to a Form</subject>
   <file>type&amp;exceptions.pdf</file>
  </lesson>
 </module>
</course>

 


The course hierarchy is represented in a treeview while the course title is the root and the subjects of the lessons are the nodes. I'm trying that each time the user selects a lesson (click on a node in the treeview), the corresponding file will be opened - according the text of the <file> that is in the same context as of the selected lesson's subject.

In order to open the file I'm using "process":

  public void OpenFile1(string fileName, XmlDocument doc)
  {
   Process process = new Process();
   try
   {
    string courseDocumentsPath = null;
    XmlNode node = doc.SelectSingleNode("/course/module/@location");
    courseDocumentsPath = node.Value;
    if(courseDocumentsPath == null)
    {
     MessageBox.Show("File doesn't exist");
    }
    else
    {
     process.StartInfo.FileName = courseDocumentsPath + "\\" + fileName;
     process.StartInfo.Verb = "Open";
     process.StartInfo.CreateNoWindow = true;
     process.Start();
    }
   }
   catch (Win32Exception e)
   {
    if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
    {
     MessageBox.Show(e.Message + ". Check the path.");
    }

    else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
    {
     MessageBox.Show(e.Message + ". You do not have permission to print this file.");
    }
   }
  }

 



Can someone please assist in how to open the corresponding file while selecting a specific subject?

Thanks a lot