Default directory using Autodesk.AutoCAD.Windows.OpenFileDialog

Default directory using Autodesk.AutoCAD.Windows.OpenFileDialog

Anonymous
Not applicable
2,188 Views
5 Replies
Message 1 of 6

Default directory using Autodesk.AutoCAD.Windows.OpenFileDialog

Anonymous
Not applicable

I am looking to get a directory name from the user but be able to utilize the Autodesk OpenFileDialog (our users have a bunch of shortcuts along the left side). So I set the AllowFoldersOnly flag, but can't seem to get it to go to a specified default directory location. In this case I'm forcing it to C:\temp, but in the full code, I will be deriving this location by other code. 

Any help or direction would be greatly appreciated.

thanks

 

 

Dim ToDialogRes As System.Windows.Forms.DialogResult

Dim flags As Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags = Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowFoldersOnly

Dim openFileDialog2 As New Autodesk.AutoCAD.Windows.OpenFileDialog("Please Select Target Directory", "C:\temp", "", "Select Directory", flags)


ToDialogRes = openFileDialog2.ShowDialog()

Select Case ToDialogRes
Case System.Windows.Forms.DialogResult.OK
TextBox1.Text = openFileDialog2.Filename

Case System.Windows.Forms.DialogResult.Cancel
MsgBox("User Cancelled")
Case Else
MsgBox("something else")
End Select

0 Likes
Accepted solutions (1)
2,189 Views
5 Replies
Replies (5)
Message 2 of 6

antonio.leonardo
Advocate
Advocate

Hi @Anonymous,

 

You can use this approach to define default user folder, in this example bellow, the captured directory will be the Documents folder of current user:

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

The type Environment.SpecialFolder is a enumerator with several options to define Windows User folder, as image bellow from .NET Framework System namespace (or mscorlib assembly):

 

folder_options.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Att,

Antonio Leonardo

exam-483-programming-in-c.png

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks Antonio for responding,  I really appreciate it, however, my problem is not finding the folder I want to set, it's the actual setting it that is not working for me.  In the code I posted I'm just hardcoding it now to c:\temp, but that is not where the dialog is opening too. That is my problem, it's not recognizing the c:\temp.

So I'm thinking I've got something wrong with the flags, or the syntax on the directory string.

 

 

 

0 Likes
Message 4 of 6

kerry_w_brown
Advisor
Advisor

 

I don't do VB much, but have a look here

https://www.theswamp.org/index.php?topic=46829.0

 

Kerry,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 5 of 6

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Try adding the DefaultIsFolder and ForceDefaultFolder flags.

 

var openFileDialog = new Autodesk.AutoCAD.Windows.OpenFileDialog(
    "Please Select Target Directory", 
    @"C:\Temp", 
    "", 
    "Select Directory",
    Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowFoldersOnly |
    Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder |
    Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.ForceDefaultFolder);

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 6

Anonymous
Not applicable

You are right Gilles, thank you so much, just had to adjust my flags...working like a charm now!

Dim flags As Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags = Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowFoldersOnly _

Or Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder _

Or Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.ForceDefaultFolder

0 Likes