none
Documents.OpenEx looks for files in the wrong folder when both Visio 2010 and 2013 are installed RRS feed

  • Question

  • Hello,

    I am trying to open a stencil in c# using the Visio Automation Reference, and depending on whether the user is using visio 2010 or 2013 I need to open a different stencil. This is an example of the code I'm using to open the stencil:

    currentStencil = ax.Document.Application.Documents.OpenEx("USTAME_M.vssx", (short)Visio.VisOpenSaveArgs.visOpenDocked);

    My code works if the user has either 2013 or 2010 installed, and if they have both installed and have recently opened Visio 2013. However, if the user has both installed and has recently opened Visio 2010, the application uses the 2010 drawing control as it should but it looks for stencils in the 2013 folder, which causes a file not found error. Does anyone know how I can get it to look in the appropriate folder?

    Thanks,

    Maddie

    • Moved by George123345 Wednesday, February 12, 2014 6:13 AM
    Tuesday, February 11, 2014 8:32 PM

Answers

  • If you are having trouble finding the install path or the folder where all the Visio stencils and templates are located through registry then you can try the following work around.

    use "ActiveDocument.Template" to get the complete path of the template file name which will give you the path of the folder where templates and stencils are present and you can use this path to open the stencil.

    • Marked as answer by Maddie Lowe Saturday, March 8, 2014 6:04 PM
    Friday, March 7, 2014 11:21 AM

All replies

  • Hi,

    This is the forum to discuss questions and feedback for Microsoft Visio,I'll move your question to the MSDN forum

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=officegeneral&filter=alltypes&sort=lastpostdesc

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    George Zhao
    TechNet Community Support

    Wednesday, February 12, 2014 6:13 AM
  • Hello Maddie,

    The best solution is to fully specify the file path, not just the name. Please read more about this in the How to: Programmatically Open Visio Documents article in MSDN.

    Also you may find the Office automation when multiple versions of Office are installed article helpful.

    Wednesday, February 12, 2014 7:29 AM
  • Hello Eugene,

    Thank you for the reply! The thing I'm trying to open is a stencil that comes with Visio though. What if Visio is installed in a different folder on different people's computers? Then the location of the stencils would be different, and hard-coding the whole path would not work.

    Also, getting the install path from the registry does not work. Here is the code I use to get the version and install path from the registry:

    RegistryKey regVersionString = Registry.ClassesRoot.OpenSubKey("Visio.Drawing\\CurVer");
    Console.WriteLine("VERSION: " + regVersionString.GetValue(""));
    Console.WriteLine(regVersionString.GetType());
    
    RegistryKey regClassId = Registry.ClassesRoot.OpenSubKey(regVersionString.GetValue("") + "\\CLSID");
    Console.WriteLine("CLSID: " + regClassId.GetValue(""));
    
    RegistryKey regInstallPath = Registry.ClassesRoot.OpenSubKey("CLSID\\" + regClassId.GetValue("") + "\\LocalServer32");
    Console.WriteLine("PATH: " + regInstallPath.GetValue(""));

    If I open Visio2013 so that Visio2013 is the most recently used version, this is what it outputs:

    VERSION: Visio.Drawing.15
    Microsoft.Win32.RegistryKey
    CLSID: {00021A15-0000-0000-C000-000000000046}
    PATH: C:\PROGRA~2\MICROS~2\Office15\VISIO.EXE

    If I open Visio2010 so that Visio2010 is the most recently used version, this is what it outputs:

    VERSION: Visio.Drawing.11
    Microsoft.Win32.RegistryKey
    CLSID: {00021A14-0000-0000-C000-000000000046}
    PATH: C:\PROGRA~2\MICROS~2\Office15\VISIO.EXE

    That paths are the same. My guess is that this is why it's looking in the wrong place for the stencils in the first place.

    This kinda seems like a bug in Visio to me.

    Saturday, March 1, 2014 6:45 PM
  • If you are having trouble finding the install path or the folder where all the Visio stencils and templates are located through registry then you can try the following work around.

    use "ActiveDocument.Template" to get the complete path of the template file name which will give you the path of the folder where templates and stencils are present and you can use this path to open the stencil.

    • Marked as answer by Maddie Lowe Saturday, March 8, 2014 6:04 PM
    Friday, March 7, 2014 11:21 AM
  • Thank you, I can use that work around. It gives me c:\program files (x86)\microsoft office\office12\1033\UMLMOD_M.VST as the path. If I replace \office12\1033\UMLMOD_M.VST with Office14\Visio Content\1033\ or Office15\Visio Content\1033\ depending on whether the user is using Visio 2010 or 2013 I can make it work. It's not as clean as a solution as I would like, but hopefully it will work on most client machines.
    Saturday, March 8, 2014 6:04 PM