Document.Document
Document()
Initializes a new instance of the Document class. Creates a blank OneNote document.
See Also
Document(string)
Initializes a new instance of the Document class. Opens an existing OneNote document from a file.
public Document(string filePath)
| Parameter | Type | Description |
|---|
| filePath | String | The file path. |
Exceptions
| exception | condition |
|---|
| UnsupportedFileFormatException | The document format is not recognized or not supported. |
| FileCorruptedException | The document appears to be corrupted and cannot be loaded. |
| IncorrectPasswordException | The document is encrypted and requires a password to open, but you supplied an incorrect password. |
| InvalidOperationException | There is a problem with the document and it should be reported to Aspose.Note developers. |
| IOException | There is an input/output exception. |
Examples
Shows how to convert a OneNote document to Notion-compatible HTML.
var dataDir = RunExamples.GetDataDir_Import();
var documentPath = Path.Combine(dataDir, "Sample.one");
// Initialize OneNote document
var document = new Document(documentPath);
// Notion client setup
var authToken = "your-notion-auth-token";
var parentPageId = "your-notion-parent-page-id";
var client = NotionClientFactory.Create(new ClientOptions
{
AuthToken = authToken
});
// Retrieve the Notion page
var page = await client.Pages.RetrieveAsync(parentPageId);
// Iterate over OneNote pages and add them to Notion
foreach (var oneNotePage in document)
{
var oneNoteAllRichText = oneNotePage.GetChildNodes<RichText>();
var pagesCreateParametersBuilder = PagesCreateParametersBuilder
.Create(new ParentPageInput { PageId = page.Id })
.AddProperty("title",
new TitlePropertyValue
{
Title = new List<RichTextBase>
{
new RichTextTextInput { Text = new Notion.Client.Text { Content = oneNotePage.Title.TitleText.Text } }
}
});
foreach (var richText in oneNoteAllRichText)
{
// Skip title, date, or time texts
if (richText.IsTitleDate || richText.IsTitleText || richText.IsTitleTime)
{
continue;
}
pagesCreateParametersBuilder.AddPageContent(new ParagraphBlock
{
Paragraph = new ParagraphBlock.Info
{
RichText = new List<RichTextBase> {
new RichTextText
{
Text = new Notion.Client.Text { Content = richText.Text }
}
}
}
});
}
// Create page in Notion
var pagesCreateParameters = pagesCreateParametersBuilder.Build();
await client.Pages.CreateAsync(pagesCreateParameters);
}
Console.WriteLine("\nOneNote document converted to Notion-compatible format successfully.");
See Also
Document(string, LoadOptions)
Initializes a new instance of the Document class. Opens an existing OneNote document from a file. Allows to specify additional options such as an encryption password.
public Document(string filePath, LoadOptions loadOptions)
| Parameter | Type | Description |
|---|
| filePath | String | The file path. |
| loadOptions | LoadOptions | Options used to load a document. Can be null. |
Exceptions
| exception | condition |
|---|
| UnsupportedFileFormatException | The document format is not recognized or not supported. |
| FileCorruptedException | The document appears to be corrupted and cannot be loaded. |
| IncorrectPasswordException | The document is encrypted and requires a password to open, but you supplied an incorrect password. |
| InvalidOperationException | There is a problem with the document and it should be reported to Aspose.Note developers. |
| IOException | There is an input/output exception. |
See Also
Document(Stream)
Initializes a new instance of the Document class. Opens an existing OneNote document from a stream.
public Document(Stream inStream)
| Parameter | Type | Description |
|---|
| inStream | Stream | The stream. |
Exceptions
| exception | condition |
|---|
| UnsupportedFileFormatException | The document format is not recognized or not supported. |
| FileCorruptedException | The document appears to be corrupted and cannot be loaded. |
| IncorrectPasswordException | The document is encrypted and requires a password to open, but you supplied an incorrect password. |
| InvalidOperationException | There is a problem with the document and it should be reported to Aspose.Note developers. |
| IOException | There is an input/output exception. |
| ArgumentException | The stream does not support reading, is null, or is already closed. |
See Also
Document(Stream, LoadOptions)
Initializes a new instance of the Document class. Opens an existing OneNote document from a stream. Allows to specify additional options such as an encryption password.
public Document(Stream inStream, LoadOptions loadOptions)
| Parameter | Type | Description |
|---|
| inStream | Stream | The stream. |
| loadOptions | LoadOptions | Options used to load a document. Can be null. |
Exceptions
| exception | condition |
|---|
| UnsupportedFileFormatException | The document format is not recognized or not supported. |
| FileCorruptedException | The document appears to be corrupted and cannot be loaded. |
| IncorrectPasswordException | The document is encrypted and requires a password to open, but you supplied an incorrect password. |
| InvalidOperationException | There is a problem with the document and it should be reported to Aspose.Note developers. |
| IOException | There is an input/output exception. |
| ArgumentException | The stream does not support reading, is null, or is already closed. |
See Also