Search code examples
c#visiovisio2013

Save visio 2013 diagram in the vsd format


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.


Solution

  • 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