Exemple #1
0
        private void ExportMany(OneNote one, List <string> pageIDs)
        {
            OneNote.ExportFormat format;
            string path;

            using (var dialog = new ExportDialog(pageIDs.Count))
            {
                if (dialog.ShowDialog(owner) != DialogResult.OK)
                {
                    return;
                }

                path   = dialog.FolderPath;
                format = dialog.Format;
            }

            string ext = null;

            switch (format)
            {
            case OneNote.ExportFormat.HTML: ext = ".htm"; break;

            case OneNote.ExportFormat.PDF: ext = ".pdf"; break;

            case OneNote.ExportFormat.Word: ext = ".docx"; break;

            case OneNote.ExportFormat.XML: ext = ".xml"; break;

            case OneNote.ExportFormat.OneNote: ext = ".one"; break;
            }

            string formatName = format.ToString();

            using (var progress = new UI.ProgressDialog())
            {
                progress.SetMaximum(pageIDs.Count);
                progress.Show(owner);

                foreach (var pageID in pageIDs)
                {
                    var page     = one.GetPage(pageID, OneNote.PageDetail.BinaryData);
                    var filename = Path.Combine(path, page.Title.Replace(' ', '_') + ext);

                    progress.SetMessage(filename);
                    progress.Increment();

                    if (format == OneNote.ExportFormat.XML)
                    {
                        SaveAsXML(page.Root, filename);
                    }
                    else
                    {
                        SaveAs(one, page.PageId, filename, format, formatName);
                    }
                }
            }

            UIHelper.ShowMessage(string.Format(Resx.SaveAsMany_Success, pageIDs.Count, path));
        }
Exemple #2
0
        private void Export(List <string> pageIDs)
        {
            OneNote.ExportFormat format;
            string path;
            bool   withAttachments;
            bool   useUnderscores;

            // dialog...

            using (var dialog = new ExportDialog(pageIDs.Count))
            {
                if (dialog.ShowDialog(owner) != DialogResult.OK)
                {
                    return;
                }

                path            = dialog.FolderPath;
                format          = dialog.Format;
                withAttachments = dialog.WithAttachments;
                useUnderscores  = dialog.UseUnderscores;
            }

            // prepare...

            string ext = null;

            switch (format)
            {
            case OneNote.ExportFormat.HTML: ext = ".htm"; break;

            case OneNote.ExportFormat.PDF: ext = ".pdf"; break;

            case OneNote.ExportFormat.Word: ext = ".docx"; break;

            case OneNote.ExportFormat.XML: ext = ".xml"; break;

            case OneNote.ExportFormat.Markdown: ext = ".md"; break;

            case OneNote.ExportFormat.OneNote: ext = ".one"; break;
            }

            // export...

            using (var progress = new UI.ProgressDialog())
            {
                progress.SetMaximum(pageIDs.Count);
                progress.Show(owner);

                var archivist = new Archivist(one);

                foreach (var pageID in pageIDs)
                {
                    var page = one.GetPage(pageID, OneNote.PageDetail.BinaryData);

                    var title = useUnderscores
                                                ? PathFactory.CleanFileName(page.Title).Replace(' ', '_')
                                                : page.Title;

                    var filename = Path.Combine(path, title + ext);

                    progress.SetMessage(filename);
                    progress.Increment();

                    if (format == OneNote.ExportFormat.HTML)
                    {
                        if (withAttachments)
                        {
                            archivist.ExportHTML(page, ref filename);
                        }
                        else
                        {
                            archivist.Export(page.PageId, filename, OneNote.ExportFormat.HTML);
                        }
                    }
                    else if (format == OneNote.ExportFormat.XML)
                    {
                        archivist.ExportXML(page.Root, filename, withAttachments);
                    }
                    else if (format == OneNote.ExportFormat.Markdown)
                    {
                        archivist.ExportMarkdown(page, filename, withAttachments);
                    }
                    else
                    {
                        archivist.Export(page.PageId, filename, format, withAttachments);
                    }
                }
            }

            SaveDefaultPath(path);

            UIHelper.ShowMessage(string.Format(Resx.SaveAsMany_Success, pageIDs.Count, path));
        }