Visio Guy

Visio Discussions => Visio 2013 Issues => Topic started by: Myra on May 14, 2013, 06:06:44 AM

Title: Save visio 2013 diagram in the vsd format programmatically
Post by: Myra on May 14, 2013, 06:06:44 AM
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;
    }

Title: Re: Save visio 2013 diagram in the vsd format programmatically
Post by: Paul Herber on May 14, 2013, 06:18:29 AM
Could well be linked to :
http://visguy.com/vgforum/index.php?topic=4641.0 (http://visguy.com/vgforum/index.php?topic=4641.0)

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

http://visguy.com/vgforum/index.php?topic=4726.0 (http://visguy.com/vgforum/index.php?topic=4726.0)

Title: Re: Save visio 2013 diagram in the vsd format programmatically
Post by: Myra on May 14, 2013, 07: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 (http://visguy.com/vgforum/index.php?topic=4712.0)

any solution for this?
Title: Re: Save visio 2013 diagram in the vsd format programmatically
Post by: JohnGoldsmith on May 14, 2013, 11: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
Title: Re: Save visio 2013 diagram in the vsd format programmatically
Post by: Myra on May 14, 2013, 01:02:26 PM
Thanks for your reply John.

Yeah,I did that and it is not working ,too.  :(
Title: Re: Save visio 2013 diagram in the vsd format programmatically
Post by: JohnGoldsmith on May 14, 2013, 02:43:03 PM
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
Title: Re: Save visio 2013 diagram in the vsd format programmatically
Post by: Myra on May 15, 2013, 05: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.