Search
Saving and Loading

Saving to files

FlowChartX provides the SaveToFile method to store diagram data to a disk file. The saved document can be reloaded later via the LoadFromFile method. The Dirty property indicates if a document has been changed since it was loaded. You can test this flag before your application exits, in order to display a confirmation dialog to the user if modified data has not been saved.

Saving as ASCII strings

Two methods, SaveToString and LoadFromString, enable saving and loading FlowChartX documents into strings of ASCII characters. That makes easy saving diagrams in database fields or embedding them as part of XML documents. You should take heed of the size requirements though. Each byte of the binary representation of a diagram requires two Unicode characters in ASCII format. That makes four times more space that the one required for saving into files or streams in binary format.

XML serialization

It is possible to save a diagram as an XML document. To do that, create an instance of the XMLWriter class, set its Document property to the FlowChart to be serialized, and call the Write or WriteToString methods. Diagrams saved that way can be loaded later using the Read or ReadFromString method of an XMLReader instance.

Since version 4.1.5, the FlowChart class provides SaveToXml and LoadFromXml methods that implement serialization in a new XML format. This new format is supported by other MindFusion diagramming components, such as Flowchart.NET, JDiagram and WpfDiagram. XMLWriter and XMLReader are still available for compatibility reasons, but they will be removed from the next major FlowChartX release.

OLE streams and compound documents

FlowChartX implements the IPersistStreamInit interface, which provide means to serialize/deserialize control contents into an OLE stream. Using methods of this interface you might save flowchart objects and properties as part of your own compound documents. Streams might also wrap memory buffers, database blobs, network transfers and more. For more information on IPersistStreamInit see the OLE documentation.

Safe for scripting mode

If embedded in a web page, FlowChartX runs in a 'safe for scripting' mode. This mode disables file creation and write operations in order to prevent malicious scripts to overwrite files on the users' hard disks. The following methods return an error if invoked in 'safe for scripting' mode: SaveToFile, SaveToBitmap and SaveToMetaFile.

.NET streams

In .NET the persisted state of  an ActiveX control is encapsulated by AxHost.State class, which implements the ISerializable interface. The AxHost.State can be retrieved  by the AxHost.OcxState property, which can be used together with objects of BinaryFormatter and  Stream classes to serialize/deserialize a FlowChartX document.

Example: To save and load FlowChartX document to/from a file you can use following VB.NET code.

VB.NET  Copy Code

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private state1 As AxHost.State

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Opens a file and serializes the FlowChartX document into it.
        Dim stream As Stream = File.Open("fcdoc.bin", FileMode.Create)
        Dim bformatter As New BinaryFormatter()
        bformatter.Serialize(stream, AxFlowChart1.OcxState)
        stream.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        'Opens a file and deserializes the FlowChartX document from it.
        Dim stream As Stream = File.Open("fcdoc.bin", FileMode.Open)
        Dim bformatter As New BinaryFormatter()
        AxFlowChart1.OcxState = CType(bformatter.Deserialize(stream), AxHost.State)
        stream.Close()

    End Sub

End Class