Author Topic: Save visio 2013 diagram in the vsd format programmatically  (Read 9215 times)

0 Members and 1 Guest are viewing this topic.

Myra

  • Newbie
  • *
  • Posts: 4
I am using visio 2013 drawing control. When I save a file as vsd it is throwing exception "File not found". However file is saved on given location. Since file is saved , I ignore the exception but on reloading the same file it is throwing "Error HRESULT E_FAIL has been returned from a call to a COM component" exception.

Everything is working fine if I used vsdx extension instead of vsd. But I save file as vsd for backward compatibility.

below is the code that all I am doing. I have also tried to set application version to 2010 but nothing is working.

private void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string fileName = "C:\\test\\mydrawing1.vsd";
            axDrawingControl1.Document.SaveAsEx(fileName, (short)VisOpenSaveArgs.visSaveAsWS);
            //axDrawingControl1.Document.SaveAs(fileName);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    private void btnReload_Click(object sender, EventArgs e)
    {
        OpenFileDialog op = new OpenFileDialog();
        op.ShowDialog();
        try
        {
            this.axDrawingControl1.Src = op.FileName;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    private void btnOpen_Click(object sender, EventArgs e)
    {
        OpenFileDialog op = new OpenFileDialog();
        op.ShowDialog();
        this.axDrawingControl1.Src = op.FileName;
    }


Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3379
    • Paul Herber's website
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

Myra

  • Newbie
  • *
  • Posts: 4
Re: Save visio 2013 diagram in the vsd format programmatically
« Reply #2 on: May 14, 2013, 02:06:57 AM »
Thanks for your reply.

I have tried visio settings for older version and my reply is same as of JleruOHeP.


"No, I dont think so. As if I open old version file first then there is no errors.
The error appears only if I save new file (and when I save that file) and try to open existing one."

here http://visguy.com/vgforum/index.php?topic=4712.0

any solution for this?

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 358
    • John Goldsmith's visLog
Re: Save visio 2013 diagram in the vsd format programmatically
« Reply #3 on: May 14, 2013, 06:34:15 AM »
If you record a macro you'll see that Visio sets the Document.Version property to 'visVersion140' prior to doing the actual save.

Does that work for you?

If you're in c# you'll need the full enum which is Visio.VisDocVersions.visVersion140

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Myra

  • Newbie
  • *
  • Posts: 4
Re: Save visio 2013 diagram in the vsd format programmatically
« Reply #4 on: May 14, 2013, 08:02:26 AM »
Thanks for your reply John.

Yeah,I did that and it is not working ,too.  :(

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 358
    • John Goldsmith's visLog
Re: Save visio 2013 diagram in the vsd format programmatically
« Reply #5 on: May 14, 2013, 09:43:03 AM »
That's a shame. 

Can you save a similar document in the main application?

And, can you open the .vsd file you generated (in the ocx) in the main application?

ie is the problem with the file or the control.

Best regards

john
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Myra

  • Newbie
  • *
  • Posts: 4
Re: Save visio 2013 diagram in the vsd format programmatically
« Reply #6 on: May 15, 2013, 12:07:40 AM »
yes, I can save similar document in main visio application.
Yes , that's file is opening in main visio application


There is no problem in file. But due to exception on saving I am unable to set the source of axDrawingControl1.Src  to another vsd(in open functionality) as it is throwing other exception.

Moreover, above scenario was working fine for ocx file generate for visio2010 but I am facing these issues on upgradation it to visio2013.