This technical tip shows how .NET developers can export Microsoft Visio diagram to XML inside their own applications using Aspose.Diagram for .NET. Aspose.Diagram for .NET lets you export diagrams to a variety of formats: image formats, HTML, SVG, SWF and XML formats:
- 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.
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.
The Sample code shows how to export VSD to VDX
[C#]
//Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");
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;
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();
diagram.Save(vdxStream, SaveFileFormat.VDX);
this.Response.End();
[VB.NET]
'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")
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
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()
diagram.Save(vdxStream, SaveFileFormat.VDX)
Me.Response.End()
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 VSX format.
[C#]
// Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");
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;
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();
diagram.Save(vsxStream, SaveFileFormat.VSX);
this.Response.End();
[VB.NET]
'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")
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
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()
diagram.Save(vsxStream, SaveFileFormat.VSX)
Me.Response.End()
Overview: Aspose.Diagram for .NET
Aspose.Diagram is a class library for working with MS Visio files & is a pure .NET alternate for MS Visio Object Model. It enables developers to work with VSD & VDX files on ASP.NET web applications, web services & Windows applications. It makes use of the advanced functionality of Visio's services to manipulate Visio docs on a server. Developer can open files & manipulate the elements of the diagram, from lines and fills, to more complex elements, and then export to native Visio formats or XML.
More about Aspose.Diagram for .NET
- Homepage of Aspose.Diagram for .NET
- Download Aspose.Diagram for .NET
No comments:
Post a Comment