How to insert a video file on OneNote page

SampleText-13.zip (2.7 MB)

Hi Amjad, Above is the requested zip file.

@SurinderH,

Thank you for providing the output OneNote document using Aspose.Note. We have logged the video and other details for your existing ticket in our database. We will look into it soon.

@SurinderH,

We found your code is not right. We think the problem is in this section of code:

using (var stream = File.OpenRead("C:\\Temp\\OneNote\\LeoVegas Ad.MP3"))
{
            // Initialize AttachedFile class object and also pass its icon path
            AttachedFile attachedFile = new AttachedFile("LeoVegas Ad", stream);

            // Add attached file
            outlineElemFile.AppendChildLast(attachedFile);
}

You need to create Attached in another way, for example like this:

AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\LeoVegas Ad.MP3");
outlineElemFile.AppendChildLast(attachedFile);

Alternatively, you may specify the file extension in FileName:

using (var stream = File.OpenRead("C:\\Temp\\OneNote\\LeoVegas Ad.MP3"))
{
            // Initialize AttachedFile class object and also pass its icon path
            AttachedFile attachedFile = new AttachedFile("LeoVegas Ad.MP3", stream);

            // Add attached file
            outlineElemFile.AppendChildLast(attachedFile);
}

Please let us know how it goes after updating your code segment and retrying your scenario/case. Did you still encounter any issues when opening the video from the output OneNote document page? If so, kindly share the output OneNote document with us, and we will further investigate.

Thanks Amjad. Sorry still do not work with the change of code.

Zip file uploaded as below:

SampleText-31.zip (117.9 KB)

The changed code is as below:

        Document doc = new Document();

        // Initialize Page class object
        Page page = new Page();

        // Initialize Title class object
        Title title = new Title();

        // Initialize TextStyle class object and set formatting properties
        ParagraphStyle defaultTextStyle = new ParagraphStyle
        {
            FontColor = Color.Black,
            FontName = "Arial",
            FontSize = 10
        };

        RichText titleText = new RichText() { ParagraphStyle = defaultTextStyle }.Append("Page 1");

        title.TitleText = titleText;

        // Set page title
        page.Title = title;

        // Initialize Outline class object
        Outline outlineFile = new Outline()
        {
            VerticalOffset = 20,
            HorizontalOffset = 5
        };

        // Initialize OutlineElement class object
        OutlineElement outlineElemFile = new OutlineElement();

        // Initialize AttachedFile class object
        //AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\LeoVegas Ad.MP3");
        //AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\Test.docx");

        //using (var stream = File.OpenRead("C:\\Temp\\OneNote\\LeoVegas Ad.MP3"))
        //{
        //    // Initialize AttachedFile class object and also pass its icon path
        //    AttachedFile attachedFile = new AttachedFile("LeoVegas Ad.MP3", stream);

        //    // Add attached file
        //    outlineElemFile.AppendChildLast(attachedFile);
        //}

        AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\LeoVegas Ad.MP3");
        outlineElemFile.AppendChildLast(attachedFile);

        //Add attached file
        //outlineElemFile.AppendChildLast(attachedFile);

        //Add outline element node
        outlineFile.AppendChildLast(outlineElemFile);

        // Add outline node
        page.AppendChildLast(outlineFile);

        // Add Page node
        doc.AppendChildLast(page);

        doc.Save("C:\\Temp\\OneNote\\SampleText-31.one");

@SurinderH,

Thanks for the new OneNote document.

We have logged your file against your issue into our database. We think the issue might be due to the peculiarities of setting up the operating system on your side. Anyways, we will be looking into it and provide you new updates on it soon.

@SurinderH,

By the way, we have tested your scenario/case on different systems. We can play the video file after opening it in the OneNote application. We need more information about the version of your operating system and the version of the OneNote application. Additionally, which application plays the file correctly when opening/saving it from File Explorer by double-clicking on it?

Untitled.jpg (59.3 KB)

Thanks Amjad. Requested information uploaded.

@SurinderH,

Thanks for environment and other details.

Also, could you provide details for the following:

Thanks Amjad. Windows Media Player plays the file correctly.

@SurinderH,

Thanks for the detail.

We have recorded it against your issue into our database. We will continue to evaluate and assess your issue and keep you informed of any updates or findings (once available).

And kindly note that same issue is with the Jpeg, word and pdf files too.

@SurinderH,

Could you please also share output OneNote file generated by Aspose.Note having JPEG, Word and PDF files embedded.

Hi Amjad, The requested information is as below:
SampleText-13.zip (2.8 MB)

        Document doc = new Document();

        // Initialize Page class object
        Page page = new Page();

        // Initialize Title class object
        Title title = new Title();

        // Initialize TextStyle class object and set formatting properties
        ParagraphStyle defaultTextStyle = new ParagraphStyle
        {
            FontColor = Color.Black,
            FontName = "Arial",
            FontSize = 10
        };

        RichText titleText = new RichText() { ParagraphStyle = defaultTextStyle }.Append("Page 1");

        title.TitleText = titleText;

        // Set page title
        page.Title = title;

        // Initialize Outline class object
        Outline outlineFile = new Outline()
        {
            VerticalOffset = 20,
            HorizontalOffset = 5
        };

        // Initialize OutlineElement class object
        OutlineElement outlineElemFile = new OutlineElement();

        // Initialize AttachedFile class object
        //AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\LeoVegas Ad.MP3");
        //AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\Test.docx");

        //using (var stream = File.OpenRead("C:\\Temp\\OneNote\\LeoVegas Ad.MP3"))
        //{
        //    // Initialize AttachedFile class object and also pass its icon path
        //    AttachedFile attachedFile = new AttachedFile("LeoVegas Ad.MP3", stream);

        //    // Add attached file
        //    outlineElemFile.AppendChildLast(attachedFile);
        //}

        AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\Image.jpg");
        outlineElemFile.AppendChildLast(attachedFile);
        outlineFile.AppendChildLast(outlineElemFile);

        outlineElemFile = new OutlineElement();
        attachedFile = new AttachedFile("C:\\Temp\\OneNote\\Test1.docx");
        outlineElemFile.AppendChildLast(attachedFile);
        outlineFile.AppendChildLast(outlineElemFile);

        outlineElemFile = new OutlineElement();
        attachedFile = new AttachedFile("C:\\Temp\\OneNote\\Test1.pdf");
        outlineElemFile.AppendChildLast(attachedFile);
        outlineFile.AppendChildLast(outlineElemFile);

        outlineElemFile = new OutlineElement();
        attachedFile = new AttachedFile("C:\\Temp\\OneNote\\LeoVegas Ad.MP3");
        outlineElemFile.AppendChildLast(attachedFile);
        outlineFile.AppendChildLast(outlineElemFile);

        outlineElemFile = new OutlineElement();
        attachedFile = new AttachedFile("C:\\Temp\\OneNote\\SkyBet ad 1.mp4");
        outlineElemFile.AppendChildLast(attachedFile);
        outlineFile.AppendChildLast(outlineElemFile);

        // Add outline node
        page.AppendChildLast(outlineFile);

        // Add Page node
        doc.AppendChildLast(page);

        doc.Save("C:\\Temp\\OneNote\\SampleText-13.one");

I have tried to attach jpg, docx, pdf, mp3 & mp4 files to explain the issue.

@SurinderH,

Thanks for the sample OneNote document containing the attachments. We will test your scenario/case on different machines and get back to you with new updates. It seems it works on some machines while it does not work (same as yours) on other machines.

Hi Amjad, Kindly let me know any update on this issue.

@SurinderH,

We did test your scenario/case and found that it works on some machines, while on others it does not. We are currently evaluating/analyzing your issue and will update you after gathering more details and findings.

Thanks Amjad

@SurinderH,

You are welcome.