HTML
JPG
VSDX
XML
VSDX
VSDX
Connect Shapes in Visio via .NET
Connect Visio Shapes using server-side APIs without any software like Microsoft or Open Office, Adobe PDF, etc.
How to Connect shapes in Visio File Using C#
In order to connect shapes in visio file, we’ll use
API which is a feature-rich, powerful and easy to use document manipulation and splitter API for C# platform. Open
package manager, search for Aspose.Diagram and install. You may also use the following command from the Package Manager Console.
Command
PM> Install-Package Aspose.Diagram
Steps to connect shapes in Visio file via C#
You need the aspose.diagram.dll to try the following workflow in your own environment.
- Instantiating a Diagram object.(or->Load the Visio file with full path.)
- Select Page via its index.
- Use the ConnectShapesViaConnector method to connect shapes in the selected page
- Save Diagram in Vsdx format.
System Requirements
Aspose.Diagram for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono or Xamarin Platforms
- Development environment like Microsoft Visual Studio
- Add reference to the Aspose.Diagram for .NET DLL in your project - Install from NuGet using the Download button above
Connect shapes - C#
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_VisioPages();
string stencil = dataDir + "Basic Shapes.vss";
// create a diagram from stencil
Diagram diagram = new Diagram(stencil);
string connectorMaster = "Dynamic connector";
string rectangleMaster = "Rectangle";
// add two rectangles to page 0
long rectangle1 = diagram.AddShape(2, 2, rectangleMaster, 0);
long rectangle2 = diagram.AddShape(2, 4, rectangleMaster, 0);
// add a connector to page 0
Shape connector1 = new Shape();
long connecter1Id = diagram.AddShape(connector1, connectorMaster, 0);
// connect the two rectangles with the connector
diagram.Pages[0].ConnectShapesViaConnector(rectangle1, ConnectionPointPlace.Right, rectangle2, ConnectionPointPlace.Bottom, connecter1Id);
// If the connection of shapes has name, we also could use connection name to connect like below
//diagram.Pages[0].ConnectShapesViaConnector(shape1, "Port7", shape2, "Port21", connecter1Id);
// The code line above is equal to the below two lines
//diagram.Pages[0].GlueShapeToConnectorBeginX(shape1, "Port7", connecter1Id);
//diagram.Pages[0].GlueShapeToConnectorEndX(shape2, "Port21", connecter1Id);
// Save diagram
diagram.Save(dataDir + "ConnectShapes_out.vsdx", SaveFileFormat.VSDX);