For use in a Visio VSTO with VB.NET, I use this code from StackOverflow to open the file dialog to let the user select the right stencil.
I do want the file dialog to open in the MyShapes directory of the user currently using Visio, but how do I get this file path from Visio?
Friend Function OpenNewStencilFileDialog() As String
Dim fd As OpenFileDialog = New OpenFileDialog()
Dim strFileName As String
fd.Title = "Open the BowTie Stencil you want to use!"
fd.InitialDirectory = "C:\"
fd.Filter = "Visio Macro-Enabled Stencil Files (*.vssm)|*.vssm|Visio Stencil Files (*.vssx)|*.vssx"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = fd.FileName
Else
strFileName = ""
End If
Return strFileName
End Function
string mypath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "My Shapes";
is, I think, the best you can do.
Super Paul thank you exactly what I was looking for!
Hi,
There's also an Application property that reflects the My Shapes path (along with other paths from the File Locations dialog).
Here's some C# (but it's the same properties in VB.NET and VBA):
void Main(){
var vApp = MyExtensions.GetRunningVisio();
Console.WriteLine(vApp.MyShapesPath);
Console.WriteLine(vApp.DrawingPaths);
Console.WriteLine(vApp.TemplatePaths);
Console.WriteLine(vApp.StencilPaths);
Console.WriteLine(vApp.HelpPaths);
Console.WriteLine(vApp.AddonPaths);
Console.WriteLine(vApp.StartupPaths);
}
MyShapesPath returns a single path, while the others are a string array split on a semi-colon character.
Best regards
John
Thank you very much John very good to see you in this forum again! :) :) :)
John, in Visual Studio I see that Application.StencilPaths is a string, but if I debug.print from the VSTO I actually get an empty string.
I might be using this incorrectly, but this is what I get.
Hi,
Does anything display in the Stencils textbox of your File Locations dialog? If that is empty then the property will be too.
Best regards
John
John I am not sure where to find this, but if from the stencils pane (see screenshot) I go to open stencil, it opens in the right location, the My Shapes directory in Documents.
Because I use OneDrive, the exact path is:
C:\Users\visisthebest\OneDrive\Documents\My Shapes
You need to use "Application.MyShapesPath" not "Application.StencilPaths".
Thank you Nikolay my mistake!
Using Application.MyShapesPath now and getting exactly the stencil location I need!