Working with Tags
Get Note Tag Details from a OneNote Document
The NoteTag class provides all the properties related to a note tag in a Microsoft OneNote document. All the OneNote file’s note tags are contained by RichText nodes of the Document object. The code example given below demonstrates how to get details about each note tag from a OneNote document.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tags();
3
4// Load the document into Aspose.Note.
5Document oneFile = new Document(dataDir + "TagFile.one");
6
7// Get all RichText nodes
8IList<RichText> nodes = oneFile.GetChildNodes<RichText>();
9
10// Iterate through each node
11foreach (RichText richText in nodes)
12{
13 foreach (var tag in richText.Tags)
14 {
15 if (tag is NoteTag)
16 {
17 NoteTag noteTag = (NoteTag)tag;
18 // Retrieve properties
19 Console.WriteLine("Completed Time: " + noteTag.CompletedTime);
20 Console.WriteLine("Create Time: " + noteTag.CreationTime);
21 Console.WriteLine("Font Color: " + noteTag.FontColor);
22 Console.WriteLine("Status: " + noteTag.Status);
23 Console.WriteLine("Label: " + noteTag.Label);
24 Console.WriteLine("Icon: " + noteTag.Icon);
25 Console.WriteLine("High Light: " + noteTag.Highlight);
26 }
27 }
28}
Tag Important Notes in the OneNote Document
The NoteTag class provides all the properties related to a note tag. Users can now tag text, image and tables. Aspose.Note for .NET APIs supports all these feature operations.
Add a New Text Node with a Tag
The code example given below demonstrates how to add a new text node with a tag in the OneNote document.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tags();
3
4// Create an object of the Document class
5Document doc = new Document();
6// Initialize Page class object
7Aspose.Note.Page page = new Aspose.Note.Page(doc);
8// Initialize Outline class object
9Outline outline = new Outline(doc);
10// Initialize OutlineElement class object
11OutlineElement outlineElem = new OutlineElement(doc);
12ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
13RichText text = new RichText(doc) { Text = "OneNote text.", ParagraphStyle = textStyle };
14text.Tags.Add(new NoteTag
15{
16 Icon = TagIcon.YellowStar,
17});
18
19// Add text node
20outlineElem.AppendChildLast(text);
21// Add outline element node
22outline.AppendChildLast(outlineElem);
23// Add outline node
24page.AppendChildLast(outline);
25// Add page node
26doc.AppendChildLast(page);
27
28dataDir = dataDir + "AddTextNodeWithTag_out.one";
29// Save OneNote document
30doc.Save(dataDir);
Add a New Image Node with a Tag
The code example given below demonstrates how to add a new Image node with a tag in the OneNote document.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tags();
3
4// Create an object of the Document class
5Document doc = new Document();
6// Initialize Page class object
7Aspose.Note.Page page = new Aspose.Note.Page(doc);
8// Initialize Outline class object
9Outline outline = new Outline(doc);
10// Initialize OutlineElement class object
11OutlineElement outlineElem = new OutlineElement(doc);
12// Load an image
13Aspose.Note.Image image = new Aspose.Note.Image(doc, dataDir + "icon.jpg");
14// Insert image in the document node
15outlineElem.AppendChildLast(image);
16image.Tags.Add(new NoteTag
17{
18 Icon = TagIcon.YellowStar,
19});
20// Add outline element node
21outline.AppendChildLast(outlineElem);
22// Add outline node
23page.AppendChildLast(outline);
24// Add page node
25doc.AppendChildLast(page);
26
27dataDir = dataDir + "AddImageNodeWithTag_out.one";
28// Save OneNote document
29doc.Save(dataDir);
Add a New Table Node with a Tag
The code example given below demonstrates how to add a new Table node with a tag in the OneNote document.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tags();
3
4// Create an object of the Document class
5Document doc = new Document();
6// Initialize Page class object
7Aspose.Note.Page page = new Aspose.Note.Page(doc);
8// Initialize TableRow class object
9TableRow row = new TableRow(doc);
10// Initialize TableCell class object
11TableCell cell = new TableCell(doc);
12// Insert cell content
13cell.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Single cell."));
14// Add cell to row node
15row.AppendChildLast(cell);
16// Initialize table node
17Table table = new Table(doc)
18{
19 IsBordersVisible = true,
20 Columns = { new TableColumn { Width = 70 } }
21};
22// Insert row node in table
23table.AppendChildLast(row);
24// Add tag to this table node
25table.Tags.Add(new NoteTag
26{
27 Icon = TagIcon.QuestionMark
28});
29
30Outline outline = new Outline(doc);
31OutlineElement outlineElem = new OutlineElement(doc);
32// Add table node
33outlineElem.AppendChildLast(table);
34// Add outline elements
35outline.AppendChildLast(outlineElem);
36page.AppendChildLast(outline);
37doc.AppendChildLast(page);
38
39dataDir = dataDir + "AddTableNodeWithTag_out.one";
40// Save OneNote document
41doc.Save(dataDir);