How to browse folder
-
It's giving error at line FolderBrowserDialog.ShowDialog()
Since my telepathic skills are a bit off today: What error? How did you initialize the dialog window? How did you declare the dialog window? Did you add the control in designer or in code?
-
Since my telepathic skills are a bit off today: What error? How did you initialize the dialog window? How did you declare the dialog window? Did you add the control in designer or in code?
I used this code for browse folder Dim theFolderBrowser As New FolderBrowserDialog theFolderBrowser.Description = "Please locate Directory..." theFolderBrowser.ShowNewFolderButton = False theFolderBrowser.RootFolder = Environment.SpecialFolder.Desktop theFolderBrowser.SelectedPath = My.Computer.FileSystem.SpecialDirectories.ProgramFiles If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then txtpath.Text = theFolderBrowser.SelectedPath Else MessageBox.Show(theFolderBrowser.SelectedPath) End If It's give me error at If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then error:Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
-
I used this code for browse folder Dim theFolderBrowser As New FolderBrowserDialog theFolderBrowser.Description = "Please locate Directory..." theFolderBrowser.ShowNewFolderButton = False theFolderBrowser.RootFolder = Environment.SpecialFolder.Desktop theFolderBrowser.SelectedPath = My.Computer.FileSystem.SpecialDirectories.ProgramFiles If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then txtpath.Text = theFolderBrowser.SelectedPath Else MessageBox.Show(theFolderBrowser.SelectedPath) End If It's give me error at If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then error:Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
Are you using this code in a separate thread than the main (GUI) thread? If so you can not do this (at least not that I'm aware off), all dialogs and GUI aspects of your program have to be executed by the main thread.
-
Are you using this code in a separate thread than the main (GUI) thread? If so you can not do this (at least not that I'm aware off), all dialogs and GUI aspects of your program have to be executed by the main thread.
Thanks for yr continuos replay.. I don't know about separate thread than the main (GUI) thread..
-
Thanks for yr continuos replay.. I don't know about separate thread than the main (GUI) thread..
Where are you calling this code? Is it in the load of a form, in the click event of a button, in a separate class, in a background worker class,...? Try adding the STAThreadattribute to the main function (the new constructor of you startupform) like the error states. I'v never encountered this error before so you might have to google it a bit. If you are just calling this dialog after the click of the event try adding a folderbrowserdialog onto the form by dragging it out off the toolbox (like you would do with any other control) and using that one.
-
Where are you calling this code? Is it in the load of a form, in the click event of a button, in a separate class, in a background worker class,...? Try adding the STAThreadattribute to the main function (the new constructor of you startupform) like the error states. I'v never encountered this error before so you might have to google it a bit. If you are just calling this dialog after the click of the event try adding a folderbrowserdialog onto the form by dragging it out off the toolbox (like you would do with any other control) and using that one.
I m calling this code in button click event.. I not found control on toolbox like folderbroswedialog.
-
I m calling this code in button click event.. I not found control on toolbox like folderbroswedialog.
What version of VS are you using because it's a standard control, it should be in your toolbox. Check the 'All Windows Forms' group. Or check if you can add it with the 'choose items' dialog (right click on an empty space in the toolbox). Also check if you have the system.windows.forms reference (you should have that but check it anyway) If you can't find it in any off those I'm afraid there is probably something wrong with your VS installation, and that's most likely why you are getting that error then. (I just copy-pasted your code in a clean project with one form and one button and it works perfectly, so check if there is nothing wrong with the references, with your installation,...)
-
What version of VS are you using because it's a standard control, it should be in your toolbox. Check the 'All Windows Forms' group. Or check if you can add it with the 'choose items' dialog (right click on an empty space in the toolbox). Also check if you have the system.windows.forms reference (you should have that but check it anyway) If you can't find it in any off those I'm afraid there is probably something wrong with your VS installation, and that's most likely why you are getting that error then. (I just copy-pasted your code in a clean project with one form and one button and it works perfectly, so check if there is nothing wrong with the references, with your installation,...)
I m using VS 2005 and .Net framework 2.0. I found folderdialog in choose items.It is already checked. But in toolbox it will not dispalyed. That's why i cn't drag from toolbox.
-
I m using VS 2005 and .Net framework 2.0. I found folderdialog in choose items.It is already checked. But in toolbox it will not dispalyed. That's why i cn't drag from toolbox.
Try unchecking it, closing the choose items dialog, reopen the choose items, rechecking it. (maybe even add it to a custom group in the toolbox so you can easily find it after (create the group then first and right click in the empty area off that group) If this doesn't work there is something wrong with your installation of VS.
-
Try unchecking it, closing the choose items dialog, reopen the choose items, rechecking it. (maybe even add it to a custom group in the toolbox so you can easily find it after (create the group then first and right click in the empty area off that group) If this doesn't work there is something wrong with your installation of VS.
Thanks a lot for yr help.. I will try this . But if u find any other code than this then plz send me.
-
Thanks a lot for yr help.. I will try this . But if u find any other code than this then plz send me.
-
I used this code for browse folder Dim theFolderBrowser As New FolderBrowserDialog theFolderBrowser.Description = "Please locate Directory..." theFolderBrowser.ShowNewFolderButton = False theFolderBrowser.RootFolder = Environment.SpecialFolder.Desktop theFolderBrowser.SelectedPath = My.Computer.FileSystem.SpecialDirectories.ProgramFiles If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then txtpath.Text = theFolderBrowser.SelectedPath Else MessageBox.Show(theFolderBrowser.SelectedPath) End If It's give me error at If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then error:Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
-
I might be mistaken but: programfolder is not part of the desktopfolder so it can't change your rootfolder or selectedpath
That doesn't brake the code. It simply means that the rootfolder property is ignored. And upon opening the dialog the program folder will be the one selected.