Home > Code > C# > How to Create OneNote File and Convert it into HTML Format inside .NET Apps

How to Create OneNote File and Convert it into HTML Format inside .NET Apps

by sher azam   on Jul 29, 2015   Category: C#   |  Views: 871    |  Points: 25   |  Gold 


This Technical tip explains how .NET developers can create and convert OneNote to HTML Format inside their .NET applications. Aspose.Note supports creating OneNote file and then saving it into html file format. To use this feature, import the Aspose.Note.Saving namespace into your application project. It has numerous valuable classes for rendering, for example HtmlSaveOptions, ImageSaveOptions, PdfSaveOptions, and SaveOptions. Aspose.Note for .NET offers the Document class that represents a OneNote file. The Document class exposes the Save method that can be called to convert the OneNote file into the HTML file format. The HtmlSaveOptions class provides options for creating HTML file, such as PageIndex, PageCount, SaveFormat and others.

Creating a OneNote and Saving into HTML using the Default Options




// [C# Code Sample]

// Initialize OneNote document
Document doc = new Document();
Aspose.Note.Page page = new Aspose.Note.Page(doc);
// default style for all text in the document.
TextStyle textStyle = new TextStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
page.Title = new Title(doc)
{
TitleText = new RichText(doc) { Text = "Title text.", DefaultStyle = textStyle },
TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), DefaultStyle = textStyle },
TitleTime = new RichText(doc) { Text = "12:34", DefaultStyle = textStyle }
};
doc.AppendChild(page);
// save as HTML format
doc.Save("out.html");

//[VB.NET Code Sample]

' Initialize OneNote document
Dim doc As New Aspose.Note.Document()
Dim page As New Aspose.Note.Page(doc)
' default style for all text in the document.
Dim textStyle As New TextStyle() With {.FontColor = System.Drawing.Color.Black, .FontName = "Arial", .FontSize = 10}
page.Title = New Title(doc) With
{
.TitleText = New RichText(doc) With {.Text = "Title text.", .DefaultStyle = textStyle},
.TitleDate = New RichText(doc) With {.Text = New DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), .DefaultStyle = textStyle},
.TitleTime = New RichText(doc) With {.Text = "12:34", .DefaultStyle = textStyle}
}
doc.AppendChild(page)
' save as HTML format
doc.Save("out.html")

// Creating a OneNote and Saving a Page Range into HTML

//The following example shows how to create a OneNote and save a page range into HTML using the HtmlSaveOptions class. It sets the PageCount and PageIndex properties.

//[C# Code Sample]

// Initialize OneNote document
Document doc = new Document();

Aspose.Note.Page page = new Aspose.Note.Page(doc);
//default style for all text in the document.
TextStyle textStyle = new TextStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
page.Title = new Title(doc)
{
TitleText = new RichText(doc) { Text = "Title text.", DefaultStyle = textStyle },
TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), DefaultStyle = textStyle },
TitleTime = new RichText(doc) { Text = "12:34", DefaultStyle = textStyle }
};
doc.AppendChild(page);
// save as HTML format
doc.Save("out.html", new HtmlSaveOptions
{
PageCount = 1,
PageIndex = 0
});

//[VB.NET Code Sample]

' Initialize OneNote document
Dim doc As New Aspose.Note.Document()

Dim page As New Aspose.Note.Page(doc)
'default style for all text in the document.
Dim textStyle As New TextStyle() With
{
.FontColor = System.Drawing.Color.Black,
.FontName = "Arial",
.FontSize = 10
}
page.Title = New Title(doc) With
{
.TitleText = New RichText(doc) With {.Text = "Title text.", .DefaultStyle = textStyle},
.TitleDate = New RichText(doc) With {.Text = New DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), .DefaultStyle = textStyle},
.TitleTime = New RichText(doc) With {.Text = "12:34", .DefaultStyle = textStyle}
}
doc.AppendChild(page)
' save as HTML format
doc.Save("out.html", New Aspose.Note.Saving.HtmlSaveOptions() With
{
.PageCount = 1,
.PageIndex = 0
})



Overview: Aspose.Note for .NET


Aspose.Note for .NET is a set of .NET components that enables developers to work with Microsoft Office OneNote files in C#, VB.NET, ASP.NET web applications, web services & Windows applications. It allows developers to open files & manipulate elements of OneNote books, from text, images & properties, to more complex elements, & then export to PNG, GIF, JPEG, BMP or PDF formats. It is a pure .NET alternative to the MS OneNote Object Model & supports OneNote 2010, OneNote® 2010 SP1 & 2013 files.

- Homepage of Aspose.Note for .NET: http://www.aspose.com/.net/note-component.aspx

- Download Aspose.Note for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.note-for-.net/default.aspx



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts