(Forms) Selecting Starting Folder

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 2 years and 5 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
Techpro
Posts: 3
Last visit: Tue Dec 26, 2023 3:12 pm

(Forms) Selecting Starting Folder

Post by Techpro »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2019
Operating system: Windows 2016
PowerShell version(s): 5.1.14393.4583

*** Please add details and screenshots as needed below. ***
Trying to create a form to export results to a CSV file. My export button will have a folderbrowserdialog control which I want to set to a starting folder of H:\Reports. This folder does exist but when I set the location I get an error that it could not be enumerated.

$buttonExportResults_Click={
#TODO: Place custom script here

$folderbrowserdialog1.RootFolder = 'H:\Reports'


}

DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

This is the error:
ERROR: Exception setting "RootFolder": "Cannot convert value "H:\Reports" to type "System.Environment+SpecialFolder". Error: "Unable to match the identifier name
ERROR: H:\Reports to a valid enumerator name. Specify one of the following enumerator names and try again:
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: (Forms) Selecting Starting Folder

Post by brittneyr »

[Topic moved by moderator]
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: (Forms) Selecting Starting Folder

Post by brittneyr »

The property, RootFolder, has the enumerated type Environment.SpecialFolder. For more information, see https://docs.microsoft.com/en-us/dotnet ... esktop-5.0. You cannot set this property with a string.

To set the starting path with a string, I recommend switching to using the FolderBrowserModernDialog control. Then you can set the starting path by setting the property InitialDirectory.
Brittney
SAPIEN Technologies, Inc.
This topic is 2 years and 5 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