コード例 #1
0
        internal string GetInsertSnipXml(OneNotePage page, string base64ImageString, string publishUrl, bool addTitle)
        {
            const string xmlFormat =
                "<?xml version=\"1.0\"?>" +
                "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2013/onenote\" ID=\"{0}\">" +  // format {0} - page.ID
                "{1}" +                                                                                           // format {1} - titleXml
                "<one:Outline>" +
                "<one:OEChildren>" +
                "<one:OE>" +
                "<one:Image format=\"png\" {2}>" +                                                                // format {2} - imageHyperlinkAttribure
                "<one:Data>{3}</one:Data>" +                                                                      // format {3} - base64ImageString
                "</one:Image>" +
                "</one:OE>" +
                "{4}" +                                                                                           // format {4} - hyperlinkOutlineXml
                "<one:OE>" +
                "<one:T/>" +
                "</one:OE>" +
                "<one:OE>" +
                "<one:T/>" +
                "</one:OE>" +
                "<one:OE>" +
                "<one:T>" +
                "<![CDATA[{5}]]>" +                                                                               // format {5} - caption
                "</one:T>" +
                "</one:OE>" +
                "<one:OE>" +
                "<one:T/>" +
                "</one:OE>" +
                "</one:OEChildren>" +
                "</one:Outline>" +
                "</one:Page>";

            string caption        = string.Format("{0} {1} - Snip", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());
            string titleXmlFormat =
                "<one:Title>" +
                "<one:OE>" +
                "<one:T>" +
                "<![CDATA[{0}]]>" +                                                                               // format {0} - caption
                "</one:T>" +
                "</one:OE>" +
                "</one:Title>";
            string       titleXml = addTitle ? string.Format(titleXmlFormat, caption) : "";
            string       imageHyperlinkAttribute   = !string.IsNullOrWhiteSpace(publishUrl) ? string.Format("hyperlink=\"{0}\"", publishUrl) : "";
            const string hyperlinkOutlineXmlFormat =
                "<one:OE>" +
                "<one:T/>" +
                "</one:OE>" +
                "<one:OE>" +
                "<one:T>" +
                "<![CDATA[{0}]]>" +                                                                               // format {0} - publishUrl
                "</one:T>" +
                "</one:OE>";
            string hyperlinkOutlineXml = !string.IsNullOrWhiteSpace(publishUrl) ? string.Format(hyperlinkOutlineXmlFormat, publishUrl) : "";

            return(string.Format(xmlFormat, page.Id, titleXml, imageHyperlinkAttribute, base64ImageString, hyperlinkOutlineXml, caption));
        }
コード例 #2
0
        internal void InsertImageIntoSection(OneNoteSection section, string imageFilePath, string publishUrl)
        {
            string newPageId;

            _oneNoteApp.CreateNewPage(section.Id, out newPageId, OneNote.NewPageStyle.npsDefault);

            OneNotePage newPage = GetPageById(newPageId);

            InsertImageIntoPage(newPage, imageFilePath, publishUrl, true);
        }
コード例 #3
0
        internal void InsertImageIntoPage(OneNotePage page, string imageFilePath, string publishUrl, bool addTitle = false)
        {
            string xmlToInsert = _oneNoteXml.GetInsertSnipXml(page, GetBase64ImageString(imageFilePath), publishUrl, addTitle);

            _oneNoteApp.UpdatePageContent(xmlToInsert, System.DateTime.MinValue, _oneNoteXmlSchema);

            // navigate to inserted Snip
            string pageContentXmlAfterInsert;

            _oneNoteApp.GetPageContent(page.Id, out pageContentXmlAfterInsert, OneNote.PageInfo.piBasic, _oneNoteXmlSchema);

            string insertedSnipObjectId = _oneNoteXml.GetInsertedSnipObjectId(pageContentXmlAfterInsert);

            _oneNoteApp.NavigateTo(page.Id, insertedSnipObjectId);
        }