Export MS Visio Diagram to XML (VDX, VTX, VSX) Formats in C# & VB.NET
Join the DZone community and get the full member experience.
Join For Free- VDX defines an XML diagram.
- VTX defines an XML template.
- VSX defines an XML stencil.
The Diagram class' constructors read a diagram and the Save method is used to save, or export, a diagram in a different file format. The code snippets in this article show how to use the Save method to save a Visio file to VDX, VTX and VSX.
Exporting VSD to VDX
VDX is a schema-based XML file format that lets you save diagrams in a format that products other than Microsoft Visio can read. It's a useful format for transferring diagrams between software applications and retaining editable data.
To export a VSD diagram to VDX first create an instance of the Diagram class and call the Diagram class' Save method to write the Visio drawing file to VDX.
Exporting from VSD to VSX
VSX is an XML format for defining stencils, the basic objects from which a diagram is built up. When a Visio file is converted to VSX, only the stencils are exported. To export a VSD diagram to VSX first you need to create an instance of the Diagram class and then call the Diagram class' Save method to write the Visio drawing file to VSX.
//The Sample code shows how to export VSD to VDX
//[C# Sample]
//Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.ContentType = "application/vnd.ms-visio";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx");
this.Response.Flush();
System.IO.Stream vdxStream = this.Response.OutputStream;
//Save input VSD as VDX
diagram.Save(vdxStream, SaveFileFormat.VDX);
this.Response.End();
//[VB.NET Code Sample]
'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")
Me.Response.Clear()
Me.Response.ClearHeaders()
Me.Response.ContentType = "application/vnd.ms-visio"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx")
Me.Response.Flush()
Dim vdxStream As System.IO.Stream = Me.Response.OutputStream
'Save inpupt VSD as VDX
diagram.Save(vdxStream, SaveFileFormat.VDX)
Me.Response.End()
//The Sample code shows how to export VSD to VSX format.
[C# Code Sample]
// Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.ContentType = "application/vnd.ms-visio";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx");
this.Response.Flush();
System.IO.Stream vsxStream = this.Response.OutputStream;
//Save input VSD as VSX
diagram.Save(vsxStream, SaveFileFormat.VSX);
this.Response.End()
//[VB.NET Code Sample]
'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")
Me.Response.Clear()
Me.Response.ClearHeaders()
Me.Response.ContentType = "application/vnd.ms-visio"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx")
Me.Response.Flush()
Dim vsxStream As System.IO.Stream = Me.Response.OutputStream
'Save input VSD as VSX
diagram.Save(vsxStream, SaveFileFormat.VSX)
Me.Response.End()
Opinions expressed by DZone contributors are their own.
Comments