![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Select folder using FolderBrowserDialog in PS? I'd like to prompt in Powershell for a folder name. I've tried the following code but it pops up without listing any folders. [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") $foldername = new-object System.Windows.Forms.folderbrowserdialog $foldername.showdialog() Doing a search shows other people have that problem in VS mentions that FolderBrowserDialog must run in a single threaded apartment. Any idea if this can be done in Powershell? Thanks, Jim |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Select folder using FolderBrowserDialog in PS? You need to set the start directory: [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") $foldername = new-object System.Windows.Forms.folderbrowserdialog $foldername.InitialDirectory = "C:\" $foldername.showdialog() --Greg "Jim Holcomb" <jim@example.net> wrote in message news:OCKZYjXUHHA.4756@TK2MSFTNGP06.phx.gbl: > I'd like to prompt in Powershell for a folder name. I've tried the > following code but it pops up without listing any folders. > > [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") > $foldername = new-object System.Windows.Forms.folderbrowserdialog > $foldername.showdialog() > > Doing a search shows other people have that problem in VS mentions that > FolderBrowserDialog must run in a single threaded apartment. > > Any idea if this can be done in Powershell? > > Thanks, > Jim |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Select folder using FolderBrowserDialog in PS? There doesn't seem to be a property InitialDirectory when I try it & there is no mention of that property in the Visual studio documentation. Could you supply a reference to it? -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Greg Wojan" wrote: > You need to set the start directory: > > [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") > $foldername = new-object System.Windows.Forms.folderbrowserdialog > $foldername.InitialDirectory = "C:\" > $foldername.showdialog() > > --Greg > > "Jim Holcomb" <jim@example.net> wrote in message > news:OCKZYjXUHHA.4756@TK2MSFTNGP06.phx.gbl: > > > I'd like to prompt in Powershell for a folder name. I've tried the > > following code but it pops up without listing any folders. > > > > [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") > > $foldername = new-object System.Windows.Forms.folderbrowserdialog > > $foldername.showdialog() > > > > Doing a search shows other people have that problem in VS mentions that > > FolderBrowserDialog must run in a single threaded apartment. > > > > Any idea if this can be done in Powershell? > > > > Thanks, > > Jim > > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Select folder using FolderBrowserDialog in PS? Documentation? What's that? <sigh> Actually I found the code snippet on the old Sapien blog as a comment to a post Jeff Hicks did using VBScript. Here's the original comment: ---------------------------- Re: Open Sesame by Gabor Ratky on Fri 24 Nov 2006 04:10 AM PST | Permanent Link [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $ofdlg = New-Object -TypeName System.Windows.Forms.OpenFileDialog $ofdlg.Title = "Select file.." $ofdlg.InitialDirectory = [System.Environment]::GetFolderPath("MyDocuments") $ofdlg.RestoreDirectory = True $ofdlg.ShowDialog() Write-Output $ofdlg.FileName ---------------------------- After I looked at the MSDN documentation I found properties called 'RootFolder' and 'SelectedPath' which appear to have similar functionality. I also found a few other references to 'InitialDirectory' on a couple of other websites. Update: Using Reflector I found 'InitialDirectory' as an inherited member from System.Windows.Forms.FileDialog. --Greg "RichS" <RichS@discussions.microsoft.com> wrote in message news:C541A070-58D3-4128-9500-44A776685525@microsoft.com: > There doesn't seem to be a property InitialDirectory when I try it & there is > no mention of that property in the Visual studio documentation. Could you > supply a reference to it? > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "Greg Wojan" wrote: > > > You need to set the start directory: > > > > [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") > > $foldername = new-object System.Windows.Forms.folderbrowserdialog > > $foldername.InitialDirectory = "C:\" > > $foldername.showdialog() > > > > --Greg > > > > "Jim Holcomb" <jim@example.net> wrote in message > > news:OCKZYjXUHHA.4756@TK2MSFTNGP06.phx.gbl: > > > > > I'd like to prompt in Powershell for a folder name. I've tried the > > > following code but it pops up without listing any folders. > > > > > > [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") > > > $foldername = new-object System.Windows.Forms.folderbrowserdialog > > > $foldername.showdialog() > > > > > > Doing a search shows other people have that problem in VS mentions that > > > FolderBrowserDialog must run in a single threaded apartment. > > > > > > Any idea if this can be done in Powershell? > > > > > > Thanks, > > > Jim > > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto Select New Folder | Dzomlija | General Discussion | 9 | 06-07-2008 01:10 PM |
| file explorer select folder on open | Michael | Vista General | 9 | 03-13-2008 04:26 PM |
| Can't select multiple emails for junk folder | chuck in austin | Vista mail | 2 | 02-18-2008 10:57 PM |
| How to select backup folder on the desktop | abintoms | Vista file management | 0 | 09-20-2007 12:52 AM |
| Cannot select more than one file or folder at a time | Corneel Heij | Vista General | 2 | 04-04-2007 10:50 AM |