Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Select folder using FolderBrowserDialog in PS?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-15-2007   #1 (permalink)
Jim Holcomb
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 SpecsSystem Spec
Old 02-16-2007   #2 (permalink)
Greg Wojan
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 SpecsSystem Spec
Old 02-16-2007   #3 (permalink)
RichS
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 SpecsSystem Spec
Old 02-20-2007   #4 (permalink)
Greg Wojan
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 SpecsSystem Spec
Closed Thread

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


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008