private void SaveAs( OneNote one, string pageId, string filename, OneNote.ExportFormat format, string formatName) { logger.WriteLine($"publishing page {pageId} to {filename}"); try { if (File.Exists(filename)) { File.Delete(filename); } one.Export(pageId, filename, format); } catch (Exception exc) { logger.WriteLine($"error publishig page as {formatName}", exc); UIHelper.ShowError(string.Format(Resx.SaveAs_Error, formatName) + "\n\n" + exc.Message); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// <summary> /// Export a page in the given format to the specified file /// </summary> /// <param name="pageId">The ID of the single page to export</param> /// <param name="filename">The output file to create/overwrite</param> /// <param name="format">The OneNote ExportFormat</param> /// <returns>True if the export was successful</returns> public bool Export(string pageId, string filename, OneNote.ExportFormat format) { logger.WriteLine($"publishing page to {filename}"); try { if (File.Exists(filename)) { File.Delete(filename); } return(one.Export(pageId, filename, format)); } catch (Exception exc) { var fmt = format.ToString(); logger.WriteLine($"error publishig page as {fmt}", exc); UIHelper.ShowError(string.Format(Resx.SaveAs_Error, fmt) + "\n\n" + exc.Message); return(false); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// <summary> /// Export a page in the given format to the specified file /// </summary> /// <param name="pageId">The ID of the single page to export</param> /// <param name="filename">The output file to create/overwrite</param> /// <param name="format">The OneNote ExportFormat</param> /// <param name="withAttachments">True if copy and relink attachments</param> /// <returns>True if the export was successful</returns> public bool Export(string pageId, string filename, OneNote.ExportFormat format, bool withAttachments = false) { logger.WriteLine($"publishing page to {filename}"); try { if (File.Exists(filename)) { File.Delete(filename); } PathFactory.EnsurePathExists(Path.GetDirectoryName(filename)); if (one.Export(pageId, filename, format)) { if (withAttachments && format == OneNote.ExportFormat.Word) { using (var word = new Helpers.Office.Word()) { var page = one.GetPage(pageId); word.LinkupAttachments(filename, page.Root); } } return(true); } return(false); } catch (Exception exc) { var fmt = format.ToString(); logger.WriteLine($"error publishig page as {fmt}", exc); UIHelper.ShowError(string.Format(Resx.SaveAs_Error, fmt) + "\n\n" + exc.Message); return(false); } }