title: OneNote NavigateTo() responds with hrObjectDoesNotExist(0x80042014) when opening a page
body: <p>I am trying to programmatically open a one note page. I am doing that in C# and using OneNote2013. I iterate through the notebooks, section groups, sections and finally pages, get a page id and try to open the page with that PageId. But it throws a ObjectDoesNotExist exception. What am I doing wrong? Code Below (OpenOneNote() at the bottom.)</p>
  
  <pre><code>public class OneNoteInterface
  {
      static Application onenoteApp = new Application();
      static XNamespace ns = null;
  
      public static string GetPage(string notebookName, string sectionGroupName, string sectionName, string pageName, out string pageXml, out string sectionId)
      {
          var onenoteApp = new Application();
          pageXml = "";
          sectionId = "";
          string notebookXml;
          onenoteApp.GetHierarchy(null, HierarchyScope.hsChildren, out notebookXml);
  
          var doc = XDocument.Parse(notebookXml);
          var ns = doc.Root.Name.Namespace;
          foreach (var notebookNode in from node in doc.Descendants(ns +
                  "Notebook")
                                       select node)
          {
              //Console.WriteLine(notebookNode.Attribute("name").Value);
              if (!notebookNode.Attribute("name").Value.Equals(notebookName))
                  continue;
              string notebookID = notebookNode.Attribute("ID").Value;
              onenoteApp.GetHierarchy(notebookID, HierarchyScope.hsChildren, out notebookXml);
              Console.WriteLine(notebookXml);
              doc = XDocument.Parse(notebookXml);
              ns = doc.Root.Name.Namespace;
              pageXml = "";
  
  
              foreach (var sectionGroupNode in from node in doc.Descendants(ns + "SectionGroup") select node)
              {
                  //Console.WriteLine("  " + sectionGroupNode.Attribute("name").Value);
  
                  if (sectionGroupNode.Attribute("name").Value.Equals(sectionGroupName))
                  {
                      string sectionGroupID = sectionGroupNode.Attribute("ID").Value;
                      onenoteApp.GetHierarchy(sectionGroupID, HierarchyScope.hsChildren, out notebookXml);
                      //Console.WriteLine(notebookXml);
                      doc = XDocument.Parse(notebookXml);
                      ns = doc.Root.Name.Namespace;
                      foreach (var sectionNode in from node in
                                                      doc.Descendants(ns + "Section")
                                                  select node)
                      {
                          Console.WriteLine("  " + sectionNode.Attribute("name").Value);
                          if (sectionNode.Attribute("name").Value.Equals(sectionName))
                          {
                              sectionId = sectionNode.Attribute("ID").Value;
                              onenoteApp.GetHierarchy(sectionId, HierarchyScope.hsChildren, out notebookXml);
                              //Console.WriteLine(notebookXml);
                              doc = XDocument.Parse(notebookXml);
                              ns = doc.Root.Name.Namespace;
                              foreach (var pageNode in from node in
                                                           doc.Descendants(ns + "Page")
                                                       select node)
                              {
                                  //Console.WriteLine("  " + pageNode.Attribute("name").Value);
                                  if (pageNode.Attribute("name").Value.Equals(pageName))
                                  {
                                      string pageId = pageNode.Attribute("ID").Value;
                                      onenoteApp.GetPageContent(pageId, out pageXml, PageInfo.piAll);
                                      doc = XDocument.Parse(pageXml);
                                      //Console.WriteLine(pageXml);
                                      return pageId;
                                  }
                              }
                              return null;
                          }
  
                      }
                      return null;
                  }
  
              }
              return null;
          }
          return null;
   }
  
  
  
  
  static void GetNamespace()
  {
     string xml;
     onenoteApp.GetHierarchy(null, HierarchyScope.hsNotebooks, out xml);
  
     var doc = XDocument.Parse(xml);
     ns = doc.Root.Name.Namespace;
  }
  
  static string GetObjectId(string parentId, HierarchyScope scope, string objectName)
  {
     string xml;
     onenoteApp.GetHierarchy(parentId, scope, out xml);
  
     var doc = XDocument.Parse(xml);
     var nodeName = "";
  
     switch (scope)
     {
        case (HierarchyScope.hsNotebooks): nodeName = "Notebook"; break;
        case (HierarchyScope.hsPages): nodeName = "Page"; break;
        case (HierarchyScope.hsSections): nodeName = "Section"; break;
        default:
        return null;
     }
  
     var node = doc.Descendants(ns + nodeName).Where(n =&gt; n.Attribute("name").Value == objectName).FirstOrDefault();
  
     return node.Attribute("ID").Value;
  }
  
  
  
      public Boolean OpenOneNote(string notebookName, string sectionGroupName, string sectionName, string pageName)
      {
  
          string sectionId = "";
          string pageXml = "";
          string pageId = GetPage(notebookName, sectionGroupName, sectionName, pageName, out pageXml, out sectionId);
          if (pageId != null)
          {
  
              onenoteApp.NavigateTo(pageId);
              return true;
          }
          return false;
  
      }
  </code></pre>