Save a diagram to a file and load from a file

Applies to: Nevron Diagram for .NET

How to save a diagram to a file and load from a file?

To save and load diagrams you need to use the Diagram Persistency Manager.

Saving documents

The persistency manager provides several methods, which can facilitate the saving of drawing and library documents to files. These are SaveDocumentToFile, SaveLibraryToFile and SaveDrawingToFile. They all have two overrides - the first one accepts only one argument - the document which must be saved, while the second one also accepts the file name in which the document must be saved. The Save methods which do not have a file name argument show a Save File Dialog. In all save methods the persistency format is determined by the file extension. For example:

[C#]
// Create a drawing document
NDrawingDocument drawing = new NDrawingDocument();
  
// create your diagram contents
  
// create a new persistency manager
NPersistencyManager persistencyManager = new NPersistencyManager();
  
// save a drawing document to XML
persistencyManager.SaveDocumentToFile(drawing, "c:\\temp\\drawing1.ndx");

[VB.NET]
' Create a drawing document
Dim drawing As New NDrawingDocument()
  
' create your diagram contents
...
  
' create a new persistency manager
Dim persistencyManager As New NPersistencyManager()
  
' save a drawing document to XML
persistencyManager.SaveDocumentToFile(drawing, "c:\temp\drawing1.ndx")

Loading documents

Analogously to document saving the manager provides the following set of methods which can help you load documents from files: LoadDocumentFromFile, LoadLibraryFromFile and LoadDrawingFromFile. The following code loads the drawing saved by the previous example:

[C#]
// Create a drawing document
NDrawingDocument drawing = new NDrawingDocument();
  
// create a new persistency manager
NPersistencyManager persistencyManager = new NPersistencyManager();
  
// load a drawing from the XML file
drawing = persistencyManager.LoadDrawingFromFile("c:\\temp\\drawing1.ndx");
  
// display the drawing
nDrawingView1.Document = drawing;

[VB.NET]
' Create a drawing document
Dim drawing As New NDrawingDocument()
  
' create a new persistency manager
Dim persistencyManager As New NPersistencyManager()
  
' load a drawing from the XML file
drawing = persistencyManager.LoadDrawingFromFile("c:\temp\drawing1.ndx")
  
' display the drawing
nDrawingView1.Document = drawing

For more information take a look at the Nevron .NET Vision Help Documentation.

Article ID: 26, Created On: 10/2/2010, Modified: 12/29/2010