1
votes

How to save diagramm in the vsd format using visio 2013 in c# visio control?

I am using the following code:

string filename = String.Format("{0}.vsd", Guid.NewGuid());
visioControl1.Document.SaveAs(temppath + filename); //Error!

This works fine under Visio 2003-2010, but in Visio 2013 it throws "File not found" exception. If I change extension to "vsdx" in the first line - it is ok again. But I have to support all the Visio versions.

1
I don't think that changing the extension to .vsd will change the file format necessarily. You'd need to have the Visio Control save the document in the correct format, not just with a different file extension.Cameron Tinker
Yep, and that is my question - how to do it? My code was written for older versions, so it works. As an example I showed that vsdx is correct format for now.JleruOHeP

1 Answers

1
votes

There is a known bug in the Visio API: The Visio Control of Visio 2013 cannot save as VSD. It'll show all sorts of strange behaviour. To deal with that, under Visio 2013 you'll have to save as vsdx and use an invisible application instance of Visio to save as vsd:

  • save as vsdx
  • make a copy of the vsdx
  • fire up a new invisible Visio application object
  • open the copy of the vsdx using the invisible app
  • save as vsd using the invisible app
  • (delete the vsdx file(s) saved in step 1 / 2)

To determine the version of Visio installed: VisioVersion = Convert.ToInt32(document.Application.Version.Replace(".", ",").Replace(",0", "")) If VisioVersion >= 15 -> Visio 2013

Please also note: to save as vsd / vsdx, you'll have to use: document.SaveEx insted of document.Save

To create an instance of an invisible Visio app, please refer to: Microsoft.Office.Interop.Visio.InvisibleApp