public static void ExportToPage(Bitmap imageToExport, OneNotePage page) { using (MemoryStream pngStream = new MemoryStream()) { imageToExport.Save(pngStream, ImageFormat.Png); string base64String = Convert.ToBase64String(pngStream.GetBuffer()); string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, imageToExport.Width, imageToExport.Height); string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.PageID, ONENOTE_NAMESPACE_2010, page.PageName }); using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) { LOG.InfoFormat("Sending XML: {0}", pageChangesXml); oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false); } } }
public static void ExportToPage(Bitmap imageToExport, OneNotePage page) { using (MemoryStream pngStream = new MemoryStream()) { imageToExport.Save(pngStream, ImageFormat.Png); string base64String = Convert.ToBase64String(pngStream.GetBuffer()); string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, imageToExport.Width, imageToExport.Height); string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.PageID, ONENOTE_NAMESPACE_2010, page.PageName }); using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) { LOG.InfoFormat("Sending XML: {0}", pageChangesXml); oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false); } } }
/// <summary> /// Get the captions of all the open word documents /// </summary> /// <returns></returns> public static List <OneNotePage> GetPages() { List <OneNotePage> pages = new List <OneNotePage>(); try { using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) { if (oneNoteApplication != null) { 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)) { reader = null; while (xmlReader.Read()) { if ("one:Page".Equals(xmlReader.Name)) { if ("true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"))) { OneNotePage page = new OneNotePage(); page.PageName = xmlReader.GetAttribute("name"); page.PageID = xmlReader.GetAttribute("ID"); pages.Add(page); // For debugging //string pageXml = ""; //oneNoteApplication.GetPageContent(page.PageID, out pageXml, PageInfo.piAll, XMLSchema.xs2010); //LOG.DebugFormat("Page XML: {0}", pageXml); } } } } } finally { if (reader != null) { reader.Dispose(); } } } } } } catch (Exception ex) { LOG.Warn("Problem retrieving onenote destinations, ignoring: ", ex); } return(pages); }
public static void ExportToPage(ISurface surfaceToUpload, OneNotePage page) { using (MemoryStream pngStream = new MemoryStream()) { SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings); string base64String = Convert.ToBase64String(pngStream.GetBuffer()); string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height); string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.PageID, ONENOTE_NAMESPACE_2010, page.PageName }); using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) { LOG.InfoFormat("Sending XML: {0}", pageChangesXml); oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false); } } }
/// <summary> /// Create a new page in the "unfiled notes section", with the title of the capture, and export the capture there. /// </summary> /// <param name="surfaceToUpload">ISurface</param> /// <returns>bool true if export worked</returns> public static bool ExportToNewPage(ISurface surfaceToUpload) { using(IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) { OneNotePage newPage = new OneNotePage(); string unfiledNotesSectionID = GetSectionID(oneNoteApplication, SpecialLocation.slUnfiledNotesSection); if(unfiledNotesSectionID != null) { string pageId = ""; oneNoteApplication.CreateNewPage(unfiledNotesSectionID, out pageId, NewPageStyle.npsDefault); newPage.ID = pageId; // Set the new name, this is automatically done in the export to page newPage.Name = surfaceToUpload.CaptureDetails.Title; return ExportToPage(oneNoteApplication, surfaceToUpload, newPage); } } return false; }
/// <summary> /// Create a new page in the "unfiled notes section", with the title of the capture, and export the capture there. /// </summary> /// <param name="surfaceToUpload">ISurface</param> /// <returns>bool true if export worked</returns> public static bool ExportToNewPage(ISurface surfaceToUpload) { using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) { OneNotePage newPage = new OneNotePage(); string unfiledNotesSectionID = GetSectionID(oneNoteApplication, SpecialLocation.slUnfiledNotesSection); if (unfiledNotesSectionID != null) { string pageId = ""; oneNoteApplication.CreateNewPage(unfiledNotesSectionID, out pageId, NewPageStyle.npsDefault); newPage.ID = pageId; // Set the new name, this is automatically done in the export to page newPage.Name = surfaceToUpload.CaptureDetails.Title; return(ExportToPage(oneNoteApplication, surfaceToUpload, newPage)); } } return(false); }
/// <summary> /// Export the capture to the specified page /// </summary> /// <param name="surfaceToUpload">ISurface</param> /// <param name="page">OneNotePage</param> /// <returns>bool true if everything worked</returns> public static bool ExportToPage(ISurface surfaceToUpload, OneNotePage page) { using(IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) { return ExportToPage(oneNoteApplication, surfaceToUpload, page); } }
/// <summary> /// Get the captions of all the open word documents /// </summary> /// <returns></returns> public static List<OneNotePage> GetPages() { List<OneNotePage> pages = new List<OneNotePage>(); try { using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) { if (oneNoteApplication != null) { 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)) { reader = null; OneNoteSection currentSection = null; OneNoteNotebook currentNotebook = null; while (xmlReader.Read()) { if ("one:Notebook".Equals(xmlReader.Name)) { string id = xmlReader.GetAttribute("ID"); if (id != null && (currentNotebook == null || !id.Equals(currentNotebook.ID))) { currentNotebook = new OneNoteNotebook(); currentNotebook.ID = xmlReader.GetAttribute("ID"); currentNotebook.Name = xmlReader.GetAttribute("name"); } } if ("one:Section".Equals(xmlReader.Name)) { string id = xmlReader.GetAttribute("ID"); if (id != null && (currentSection == null || !id.Equals(currentSection.ID))) { currentSection = new OneNoteSection(); currentSection.ID = xmlReader.GetAttribute("ID"); currentSection.Name = xmlReader.GetAttribute("name"); currentSection.Parent = currentNotebook; } } if ("one:Page".Equals(xmlReader.Name)) { // Skip deleted items if ("true".Equals(xmlReader.GetAttribute("isInRecycleBin"))) { continue; } OneNotePage page = new OneNotePage(); page.Parent = currentSection; page.Name = xmlReader.GetAttribute("name"); page.ID = xmlReader.GetAttribute("ID"); if (page.ID == null || page.Name == null) { continue; } page.IsCurrentlyViewed = "true".Equals(xmlReader.GetAttribute("isCurrentlyViewed")); pages.Add(page); } } } } finally { if (reader != null) { reader.Dispose(); } } } } } } catch (COMException cEx) { if (cEx.ErrorCode == unchecked((int)0x8002801D)) { LOG.Warn("Wrong registry keys, to solve this remove the OneNote key as described here: http://microsoftmercenary.com/wp/outlook-excel-interop-calls-breaking-solved/"); } LOG.Warn("Problem retrieving onenote destinations, ignoring: ", cEx); } catch (Exception ex) { LOG.Warn("Problem retrieving onenote destinations, ignoring: ", ex); } pages.Sort(delegate(OneNotePage p1, OneNotePage p2) { if(p1.IsCurrentlyViewed || p2.IsCurrentlyViewed) { return p2.IsCurrentlyViewed.CompareTo(p1.IsCurrentlyViewed); } return p1.DisplayName.CompareTo(p2.DisplayName); }); return pages; }
/// <summary> /// Export the capture to the specified page /// </summary> /// <param name="oneNoteApplication">IOneNoteApplication</param> /// <param name="surfaceToUpload">ISurface</param> /// <param name="page">OneNotePage</param> /// <returns>bool true if everything worked</returns> private static bool ExportToPage(IOneNoteApplication oneNoteApplication, ISurface surfaceToUpload, OneNotePage page) { if(oneNoteApplication == null) { return false; } using (MemoryStream pngStream = new MemoryStream()) { SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings); string base64String = Convert.ToBase64String(pngStream.GetBuffer()); string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height); string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.ID, ONENOTE_NAMESPACE_2010, page.Name }); LOG.InfoFormat("Sending XML: {0}", pageChangesXml); oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false); try { oneNoteApplication.NavigateTo(page.ID, null, false); } catch(Exception ex) { LOG.Warn("Unable to navigate to the target page", ex); } return true; } }
/// <summary> /// Export the capture to the specified page /// </summary> /// <param name="oneNoteApplication">IOneNoteApplication</param> /// <param name="surfaceToUpload">ISurface</param> /// <param name="page">OneNotePage</param> /// <returns>bool true if everything worked</returns> private static bool ExportToPage(IOneNoteApplication oneNoteApplication, ISurface surfaceToUpload, OneNotePage page) { if (oneNoteApplication == null) { return(false); } using (MemoryStream pngStream = new MemoryStream()) { SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings); string base64String = Convert.ToBase64String(pngStream.GetBuffer()); string imageXmlStr = string.Format(XmlImageContent, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height); string pageChangesXml = string.Format(XmlOutline, imageXmlStr, page.ID, OnenoteNamespace2010, page.Name); Log.InfoFormat("Sending XML: {0}", pageChangesXml); oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false); try { oneNoteApplication.NavigateTo(page.ID, null, false); } catch (Exception ex) { Log.Warn("Unable to navigate to the target page", ex); } return(true); } }
/// <summary> /// Export the capture to the specified page /// </summary> /// <param name="surfaceToUpload">ISurface</param> /// <param name="page">OneNotePage</param> /// <returns>bool true if everything worked</returns> public static bool ExportToPage(ISurface surfaceToUpload, OneNotePage page) { using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) { return(ExportToPage(oneNoteApplication, surfaceToUpload, page)); } }
/// <summary> /// Get the captions of all the open word documents /// </summary> /// <returns></returns> public static List <OneNotePage> GetPages() { List <OneNotePage> pages = new List <OneNotePage>(); try { using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) { if (oneNoteApplication != null) { // ReSharper disable once RedundantAssignment 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)) { reader = null; OneNoteSection currentSection = null; OneNoteNotebook currentNotebook = null; while (xmlReader.Read()) { if ("one:Notebook".Equals(xmlReader.Name)) { string id = xmlReader.GetAttribute("ID"); if (id != null && (currentNotebook == null || !id.Equals(currentNotebook.ID))) { currentNotebook = new OneNoteNotebook { ID = xmlReader.GetAttribute("ID"), Name = xmlReader.GetAttribute("name") }; } } if ("one:Section".Equals(xmlReader.Name)) { string id = xmlReader.GetAttribute("ID"); if (id != null && (currentSection == null || !id.Equals(currentSection.ID))) { currentSection = new OneNoteSection { ID = xmlReader.GetAttribute("ID"), Name = xmlReader.GetAttribute("name"), Parent = currentNotebook }; } } if ("one:Page".Equals(xmlReader.Name)) { // Skip deleted items if ("true".Equals(xmlReader.GetAttribute("isInRecycleBin"))) { continue; } OneNotePage page = new OneNotePage { Parent = currentSection, Name = xmlReader.GetAttribute("name"), ID = xmlReader.GetAttribute("ID") }; if (page.ID == null || page.Name == null) { continue; } page.IsCurrentlyViewed = "true".Equals(xmlReader.GetAttribute("isCurrentlyViewed")); pages.Add(page); } } } } finally { reader?.Dispose(); } } } } } catch (COMException cEx) { if (cEx.ErrorCode == unchecked ((int)0x8002801D)) { Log.Warn("Wrong registry keys, to solve this remove the OneNote key as described here: http://microsoftmercenary.com/wp/outlook-excel-interop-calls-breaking-solved/"); } Log.Warn("Problem retrieving onenote destinations, ignoring: ", cEx); } catch (Exception ex) { Log.Warn("Problem retrieving onenote destinations, ignoring: ", ex); } pages.Sort(delegate(OneNotePage p1, OneNotePage p2) { if (p1.IsCurrentlyViewed || p2.IsCurrentlyViewed) { return(p2.IsCurrentlyViewed.CompareTo(p1.IsCurrentlyViewed)); } return(string.Compare(p1.DisplayName, p2.DisplayName, StringComparison.Ordinal)); }); return(pages); }
/// <summary> /// Get the captions of all the open word documents /// </summary> /// <returns></returns> public static List<OneNotePage> GetPages() { List<OneNotePage> pages = new List<OneNotePage>(); try { using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) { if (oneNoteApplication != null) { string notebookXml = ""; oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010); if (!string.IsNullOrEmpty(notebookXml)) { LOG.Debug(notebookXml); using (StringReader reader = new StringReader(notebookXml)) { using (XmlTextReader xmlReader = new XmlTextReader(reader)) { while (xmlReader.Read()) { if ("one:Page".Equals(xmlReader.Name)) { if ("true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"))) { OneNotePage page = new OneNotePage(); page.PageName = xmlReader.GetAttribute("name"); page.PageID = xmlReader.GetAttribute("ID"); pages.Add(page); // For debugging //string pageXml = ""; //oneNoteApplication.GetPageContent(page.PageID, out pageXml, PageInfo.piAll, XMLSchema.xs2010); //LOG.DebugFormat("Page XML: {0}", pageXml); } } } } } } } } } catch (Exception ex) { LOG.Warn("Problem retrieving onenote destinations, ignoring: ", ex); } return pages; }
public OneNoteDestination(OneNotePage page) { this.page = page; }