C# & VB.NET Code Samples for Exporting Microsoft Visio Diagram to XML


/ Published in: Java
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. Exporting VSD to VDX
  2.  
  3. 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.
  4. 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.
  5.  
  6. The Sample code shows how to export VSD to VDX
  7.  
  8. [C#]
  9.  
  10. //Call the diagram constructor to load diagram from a VSD file
  11. Diagram diagram = new Diagram("D:\\Drawing1.vsd");
  12.  
  13. this.Response.Clear();
  14. this.Response.ClearHeaders();
  15. this.Response.ContentType = "application/vnd.ms-visio";
  16. this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx");
  17. this.Response.Flush();
  18. System.IO.StreamvdxStream = this.Response.OutputStream;
  19.  
  20. //Save input VSD as VDX
  21. diagram.Save(vdxStream, SaveFileFormat.VDX);
  22. this.Response.End();
  23.  
  24. [VB.NET]
  25.  
  26. 'Call the diagram constructor to load diagram from a VSD file
  27. Dim diagram As New Diagram("D:\Drawing1.vsd")
  28.  
  29. Me.Response.Clear()
  30. Me.Response.ClearHeaders()
  31. Me.Response.ContentType = "application/vnd.ms-visio"
  32. Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx")
  33. Me.Response.Flush()
  34. Dim vdxStream As System.IO.Stream = Me.Response.OutputStream
  35.  
  36. 'Save inpupt VSD as VDX
  37. diagram.Save(vdxStream, SaveFileFormat.VDX)
  38. Me.Response.End()
  39.  
  40. Exporting from VSD to VSX
  41.  
  42. 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.
  43.  
  44. The Sample code shows how to export VSD to VSX format.
  45.  
  46. [C#]
  47.  
  48.  
  49. // Call the diagram constructor to load diagram from a VSD file
  50. Diagram diagram = new Diagram("D:\\Drawing1.vsd");
  51.  
  52. this.Response.Clear();
  53. this.Response.ClearHeaders();
  54. this.Response.ContentType = "application/vnd.ms-visio";
  55. this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx");
  56. this.Response.Flush();
  57. System.IO.StreamvsxStream = this.Response.OutputStream;
  58.  
  59. //Save input VSD as VSX
  60. diagram.Save(vsxStream, SaveFileFormat.VSX);
  61. this.Response.End();
  62.  
  63. [VB.NET]
  64.  
  65.  
  66. 'Call the diagram constructor to load diagram from a VSD file
  67. Dim diagram As New Diagram("D:\Drawing1.vsd")
  68.  
  69. Me.Response.Clear()
  70. Me.Response.ClearHeaders()
  71. Me.Response.ContentType = "application/vnd.ms-visio"
  72. Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx")
  73. Me.Response.Flush()
  74. Dim vsxStream As System.IO.Stream = Me.Response.OutputStream
  75.  
  76. 'Save input VSD as VSX
  77. diagram.Save(vsxStream, SaveFileFormat.VSX)
  78. Me.Response.End()

URL: http://www.aspose.com/docs/display/diagramnet/Export+Diagram+to+XML

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.