Combine MS Visio Diagrams using C#

Microsoft Visio is a popular vector graphics application that allows the creation of a wide range of diagrams such as flowcharts, data flow diagrams, business process models, etc. In certain cases, we may need to combine or merge two or more Visio diagrams (VSDX or VDX) into a single Visio file programmatically. In this article, we will learn how to combine Visio diagrams using C#.

The article shall cover the following topics:

  1. C# Visio API to Combine Diagrams and Flowcharts
  2. Combine MS Visio VSDX Files using C#
  3. Combine MS Visio VDX Files using C#
  4. Merge Multiple MS Visio Files using C#

C# Visio API to Combine Diagrams and Flowcharts

To combine two or more Visio files, we will be using the Aspose.Diagram for .NET API. It is a feature-rich API that allows you to create, manipulate & convert native Visio formats from within your .NET applications.

The Diagram class of the API represents the root element of the Visio objects hierarchy. It offers various methods and properties to work with Visio objects. The Combine() method of this class combines another Diagram object with the current. The Save() method of this class saves the diagram data to the file in a specified SaveFileFormat. The SaveFileFormat enumeration provides supported saving diagram format selection.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Diagram

Combine MS Visio VSDX Files using C#

We can easily merge two MS Visio VSDX files by following the steps given below:

  1. Firstly, load the Visio file using the Diagram class.
  2. Next, load another Visio file using the Diagram class.
  3. After that, call the Diagram.Combine() method with the Diagram object to combine with as an argument.
  4. Finally, save using the Diagram.Save(Sring fileName, SaveFileFormat.VSDX) method to save the merged file as VSDX.

The following code sample shows how to combine two MS Visio VSDX diagram files in C#.

Combine MS Visio VDX Files using C#

Similarly, we can merge two MS Visio VDX files by following the steps mentioned earlier. However, we just need to load VDX files instead of VSDX files. We also need to save the merged files as VDX in the last step.

The following code sample shows how to combine two MS Visio VDX diagram files in C#.

Merge Multiple MS Visio Files using C#

We can easily merge multiple MS Visio files by following the steps given below:

  1. Firstly, load the Visio file using the Diagram class.
  2. Next, load another Visio file using the Diagram class.
  3. Optionally, repeat the above step to load more files.
  4. Next, call the Diagram.Combine() method with the Diagram object to combine with as an argument.
  5. After that, repeat the above step for all loaded files to combine.
  6. Finally, save using the Diagram.Save(Sring fileName, SaveFileFormat.VSDX) method to save the merged file as VSDX.

The following code sample shows how to combine multiple MS Visio diagram files in C#.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to merge two or more VSDX files in C#. We have also seen how to combine VDX files into a single file programmatically. Besides, you can learn more about Aspose.Diagram for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our forum.

See Also