A better folderbrowserdialog - follow up

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sebus05
Posts: 3
Last visit: Thu Jun 22, 2017 3:17 am

A better folderbrowserdialog - follow up

Post by sebus05 »

As the original topic is locked:

viewtopic.php?t=8662

I can not make it work, it only errors out, no matter how I import the function.

Am I just being plain silly (probably)

But help would be appreciated

Code: Select all

Import-module .\BuildDialog.ps1 -Force

OR

. .\BuildDialog.ps1

Code: Select all

New-Object : Cannot find type [FolderSelect.FolderSelectDialog]: verify that the assembly containing this type is
loaded.
At C:\selectdirUNC.ps1:5 char:8
+ $fsd = New-Object FolderSelect.FolderSelectDialog
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'Title' cannot be found on this object. Verify that the property exists and can be set.
At C:\selectdirUNC.ps1:6 char:5
+     $fsd.Title = "What to select";
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\selectdirUNC.ps1:7 char:5
+     $fsd.ShowDialog() | Out-Null
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: A better folderbrowserdialog - follow up

Post by Alexander Riedel »

We need to know what OS and PowerShell version.
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A better folderbrowserdialog - follow up

Post by jvierra »

To use this function outside of a controlset you need to load and execute the function:
  1. . .\BuildDialog.ps1
  2. BuildDialog
  3. $fsd = New-Object FolderSelect.FolderSelectDialog
  4. $fsd.ShowDialog()
All of this is done for you with PowerShell Studio. Just add the control set to the form.
User avatar
sebus05
Posts: 3
Last visit: Thu Jun 22, 2017 3:17 am

Re: A better folderbrowserdialog - follow up

Post by sebus05 »

Thanks a lot!

I was missing single line

BuildDialog

Perfect solution!

Code: Select all

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14393  1198
sebus
User avatar
sebus05
Posts: 3
Last visit: Thu Jun 22, 2017 3:17 am

Re: A better folderbrowserdialog - follow up

Post by sebus05 »

Is there a way to add the "starting" folder where the dialog first opens?

sebus
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A better folderbrowserdialog - follow up

Post by jvierra »

This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked