To save directly to a Visio Drawing file call any of the SaveToLocalFile or SaveToStream methods of the drawing view, for example:
Save to a Visio Drawing file |
Copy Code
|
---|---|
drawingView.SaveToLocalFile(@"C:\VisioDrawing.vsdx");
|
You can also use the SaveToFileAsync method. As its name shows the SaveToFileAsync method is asynchronous. If you want to be notified when it has finished saving the Visio drawing to file, call the Then method of the promise it returns and add a delegate like this:
Save to Visio Drawing file and get notified when completed |
Copy Code
|
---|---|
drawingView.SaveToFileAsync("C:\\VisioDrawing.vsdx").Then( delegate (bool success) { // Export to Visio completed } ); |
The SaveToStream method is synchornious and blocks execution until it completes.
Save to Visio Drawing stream |
Copy Code
|
---|---|
drawingView.SaveToStream(stream, NDrawingFormat.Visio); |
If you want to save a drawing document that is not placed in a drawing view to a file or stream use the NDrawingFormat.Visio.SaveToFileAsync or the NDrawingFormat.Visio.SaveToStream methods.
To customize the Visio drawing export process you can pass an NVisioDrawingSaveSettings instance to the Save method. It contains the following properties:
- CompressionLevel - the compression level to apply when creating the VSDX file/stream. By default set to BestCompression.
- EmbedPreview - determines whether to embed a preview (in EMF format) of the document in the generated Visio package. By default set to true. If you are after maximum performance, set this property to false to instruct the Visio exporter not to generate and embed a preview of the document in the resulting Visio package.
Using Visio Drawing save settings |
Copy Code
|
---|---|
NVisioDrawingSaveSettings visioSaveSettings = new NVisioDrawingSaveSettings(); visioSaveSettings.CompressionLevel = ENCompressionLevel.BestSpeed; visioSaveSettings.EmbedPreview = false; drawingView.SaveToLocalFile(@"C:\VisioDrawing.vsdx", NDrawingFormat.Visio, visioSaveSettings); |
The example above configures the Visio Drawing export for maximum performance by setting the CompressionLevel to BestSpeed and disabling the generation and embedding of document preview in the resulting Visio package.