Save a OneNote Document

Saving a Document to OneNote Format

How does it work?

The save method exposed by the API lets you save the document to OneNote format. The following three overloaded members provide the option to save the document in OneNote format.

1string inputFile = "Sample1.one";
2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
3string outputFile = "SaveDocToOneNoteFormat_out.one";
4            
5Document doc = new Document(dataDir + inputFile);
6doc.Save(dataDir + outputFile);

Saving a Document Using Save Options

1string inputFile = "Sample1.one";
2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
3string outputFile = "SaveDocToOneNoteFormatUsingOnesaveoptions_out.one";
4
5Document document = new Document(dataDir + inputFile);
6
7document.Save(dataDir + outputFile, new OneSaveOptions());

Saving a Document Using Save Format

1string inputFile = "Sample1.one";
2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
3string outputFile = "SaveDocToOneNoteFormatUsingSaveFormat_out.one";
4
5Document document = new Document(dataDir + inputFile);
6
7document.Save(dataDir + outputFile, SaveFormat.One);

Save OneNote Document to a Stream

Users can pass a stream object to the Document.Save(Stream, SaveFormat) method. When saving to a stream, you must specify the save format explicitly.

The following code example demonstrates how to save a document to a stream.

 1// The path to the documents directory.
 2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
 3
 4// Load the document into Aspose.Note.
 5Document doc = new Document(dataDir + "Aspose.one");
 6
 7MemoryStream dstStream = new MemoryStream();
 8doc.Save(dstStream, SaveFormat.Pdf);
 9
10// Rewind the stream position back to zero so it is ready for next reader.
11dstStream.Position = 0;

Specify OneNote Save Options

There are overloaded methods for Document.Save method that accept a SaveOptions object. This should be an object of a class derived from the SaveOptions class. Each save format has a corresponding class that holds save options for that format, for example, there is PdfSaveOptions for SaveFormat.Pdf and OneSaveOptions for SaveFormat.One.

The following code example demonstrates how to set save options before saving a document to PDF.

 1// The path to the documents directory.
 2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
 3
 4// Load the document into Aspose.Note.
 5Document doc = new Document(dataDir + "Aspose.one");
 6
 7// Initialize PdfSaveOptions object
 8PdfSaveOptions opts = new PdfSaveOptions();
 9// Set page index
10opts.PageIndex = 2;
11// Set page count
12opts.PageCount = 3;
13
14//specify compression if required
15opts.ImageCompression = Saving.Pdf.PdfImageCompression.Jpeg;
16opts.JpegQuality = 90;
17
18dataDir = dataDir + "Document.SaveWithOptions_out.pdf";
19doc.Save(dataDir, opts);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.