We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to save a diagram in code behind (C#)


We have a requirement to create a diagram template programmatically - a simple diagram that will be opened later by the user.  There is no UI involved.

I have used some of the code from your online demos, but I'm at a point where I need to save the diagram.
Ideally I'd like to get a string that I can save to our database, much like I'm currently doing on the client.
Is there a diagram.save equivalent in code behind?

Here's what I have now (it should look familiar):

protected void CreateDiagramStub(String newActivityId)
        Diagram diagram = new Diagram();
        SwimLane swimlane = new SwimLane();
        swimlane.Type = "swimlane";
        swimlane.Name = "swimlane";
        Header header = new Header();
        header.Text = "Process / Activity";
        header.Height = 50;
        header.FillColor = darkColor;
        header.FontSize = 11;
        swimlane.Header = header;
        swimlane.FillColor = darkColor;
        swimlane.Orientation = "horizontal";
        swimlane.OffsetX = 350;
        swimlane.OffsetY = 290;
        swimlane.Height = 100;
        swimlane.Width = 650;
        swimlane.Lanes = CreateLanes();
        swimlane.Phases = CreatePhases();
        //String saveData = diagram.Save("myDiagram"); // What I'd like to do!

Any suggestions?



1 Reply

SG Shyam G Syncfusion Team December 3, 2014 12:18 PM UTC

 Hi  Jim


Thanks for using Syncfusion products.


Please refer the below code snippet to retrieve the JSON string in the server side and later you can save the same string in the database. We have attached sample below


     SerializeObject serialize = new SerializeObject();

   //retrieve JSON string

     string save = serialize.SerializeToJson(DiagramContent.Model);


Please let me know if any concerns.



Shyam G

Attachment: serializesample_55218507.zip

Live Chat Icon For mobile
Up arrow icon