I want to insert video file on onenote page using C#. Kindly help me to achieve this.
Do you need to embed the video as attachment or you need to insert an online video? Could you please share a sample OneNote document having a video file inserted? We will look into it soon.
P.S. Please zip the document before attaching it here.
Thanks Amjad.
I want to embed the video as attachment.
Below is the code:
Aspose.Note.License license = new Aspose.Note.License();
license.SetLicense(“Aspose.Notefor.NET.lic”);
Document doc = new Document();
// Initialize Page class object
Page page = new Page();
// Initialize Outline class object
Outline outlineFile = new Outline();
// Initialize OutlineElement class object
OutlineElement outlineElemFile = new OutlineElement();
// Initialize AttachedFile class object
AttachedFile attachedFile = new AttachedFile("C:\\Temp\\OneNote\\Ad.MP3");
// 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\\SampleTextImgandDocx.one");
Your code is right. Do you find any issue with it, please elaborate with sample files (video file, output document) if you still find any issue? We will check your issue soon.
Please check the zip file that contained onenote file. When I click on mp3 file nothing happens.
Thanks for the sample document.
I was able to reproduce the issue as you mentioned. I found that video files are not inserted/embedded properly as attachment into OneNote page. I tested it with a simple MP4 file and found the issue. In the output document video attachment is added as a simple/static text.
We require though evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): NOTENET-5834
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thanks Amjad.
We again tested your scenario/case using the following sample code. We used a simple MP4 video to be inserted into OneNote document.
e.g.
Sample code:
Aspose.Note.Document doc = new Aspose.Note.Document();
// Initialize Page class object
Aspose.Note.Page page = new Aspose.Note.Page();
// Initialize Outline class object
Aspose.Note.Outline outlineFile = new Aspose.Note.Outline();
// Initialize OutlineElement class object
Aspose.Note.OutlineElement outlineElemFile = new Aspose.Note.OutlineElement();
// Initialize AttachedFile class object
Aspose.Note.AttachedFile attachedFile = new Aspose.Note.AttachedFile("g:\\test2\\problem.mp4");
// 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("g:\\test2\\SampleDocument1.one");
I opened the “SampleDocument1.one” file into OneNote application. The video can be seen into the document. I right-click on the video and click “Open Original” option, it prompts me message(s) and I click on “Yes/Ok” to open it. The video is opened fine into the media player. In short, it works Ok. I am using Aspose.Note for .NET v24.2 (please try it if you are not already using it). Please find attached the output OneNote file created with above code segment.
SampleDocument1.zip (582.8 KB)
(Note: The icon of the video file in the document is simple text, so you got to right-click on it and click the relevant option to open the file)
Could you please try the scenario/case with latest version and let us know know if you still find any issue.
Thanks Amjad.
Yes it works but it opens the video from original location and in your example the location is g:\test2\problem.mp4
If you remove the mp4 from the folder then mp4 do not play from OneNote.
Actually we want to embed the mp4 on OneNote.
Please sort out this issue.
I think it is same with MS OneNote application’s “File Attachment” feature, is not it? Could you please share a sample OneNote document having a sample video as embedded resource? We will check it on how to do it via Aspose.Note API.
Thanks for the sample document.
We understand now that you need to embed video into OneNote document instead of inserting it as a linked video. We have recorded your requirements with sample document against your existing ticket “NOTENET-5834” into our database. We will be looking into it soon.
Once we have an update on it, we will let you know.
Hi Amjad, Do you have any idea how much time this development will take? We want to start using this Aspose.Note component but we can’t start development without this issue resolving and other parsing Html.
Please spare us little time to evaluate your requested feature/requirements in details. We will get back to you with new updates or ETA on it.
To evaluate the issue precisely, we need to know the exact version details of your OneNote application. Please provide the necessary information. To get the version details, you need to open File → Account (in the OneNote app). Also, share the OneNote file created using the Aspose.Note library using the code segment.
Thanks Amjad. The version of OneNote application is Microsoft 365 Apps for Business.
The 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", stream);
// Add attached file
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-13.one");
Thank you for the version details and code snippet. Could you also please zip and attach the output file “SampleText-13.one” which is generated by using your code segment? This will help us evaluate your issue/requirements precisely.