/// <summary> /// Retrieve the Section ID for the specified special location /// </summary> /// <param name="oneNoteApplication"></param> /// <param name="specialLocation">SpecialLocation</param> /// <returns>string with section ID</returns> private static string GetSectionId(IOneNoteApplication oneNoteApplication, SpecialLocation specialLocation) { if (oneNoteApplication == null) { return(null); } // ReSharper disable once RedundantAssignment var unfiledNotesPath = ""; oneNoteApplication.GetSpecialLocation(specialLocation, out unfiledNotesPath); // ReSharper disable once RedundantAssignment var notebookXml = ""; oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010); if (string.IsNullOrEmpty(notebookXml)) { return(null); } Log.Debug().WriteLine(notebookXml); StringReader reader = null; try { reader = new StringReader(notebookXml); using (var xmlReader = new XmlTextReader(reader)) { while (xmlReader.Read()) { if (!"one:Section".Equals(xmlReader.Name)) { continue; } var id = xmlReader.GetAttribute("ID"); var path = xmlReader.GetAttribute("path"); if (unfiledNotesPath.Equals(path)) { return(id); } } } } finally { reader?.Dispose(); } return(null); }
/// <summary> /// Retrieve the Section ID for the specified special location /// </summary> /// <param name="oneNoteApplication"></param> /// <param name="specialLocation">SpecialLocation</param> /// <returns>string with section ID</returns> private static string GetSectionID(IOneNoteApplication oneNoteApplication, SpecialLocation specialLocation) { if (oneNoteApplication == null) { return(null); } string unfiledNotesPath = ""; oneNoteApplication.GetSpecialLocation(specialLocation, out unfiledNotesPath); string notebookXml = ""; oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010); if (!string.IsNullOrEmpty(notebookXml)) { LOG.Debug(notebookXml); StringReader reader = null; try { reader = new StringReader(notebookXml); using (XmlTextReader xmlReader = new XmlTextReader(reader)) { while (xmlReader.Read()) { if ("one:Section".Equals(xmlReader.Name)) { string id = xmlReader.GetAttribute("ID"); string path = xmlReader.GetAttribute("path"); if (unfiledNotesPath.Equals(path)) { return(id); } } } } } finally { if (reader != null) { reader.Dispose(); } } } return(null); }
/// <summary> /// Retrieve the Section ID for the specified special location /// </summary> /// <param name="oneNoteApplication"></param> /// <param name="specialLocation">SpecialLocation</param> /// <returns>string with section ID</returns> private static string GetSectionID(IOneNoteApplication oneNoteApplication, SpecialLocation specialLocation) { if(oneNoteApplication == null) { return null; } string unfiledNotesPath = ""; oneNoteApplication.GetSpecialLocation(specialLocation, out unfiledNotesPath); string notebookXml = ""; oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010); if(!string.IsNullOrEmpty(notebookXml)) { LOG.Debug(notebookXml); StringReader reader = null; try { reader = new StringReader(notebookXml); using(XmlTextReader xmlReader = new XmlTextReader(reader)) { while(xmlReader.Read()) { if("one:Section".Equals(xmlReader.Name)) { string id = xmlReader.GetAttribute("ID"); string path = xmlReader.GetAttribute("path"); if(unfiledNotesPath.Equals(path)) { return id; } } } } } finally { if(reader != null) { reader.Dispose(); } } } return null; }