folderbrowsermoderndialog reverting to non modern on Win 10

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 4 years and 6 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
RobBrown
Posts: 13
Last visit: Tue Oct 15, 2019 10:38 am

folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown »

Using PowerShell Studio 2019 64bit Version 5.6.167
Script Engine: PowerShell V5 Host (Windows Forms) - STA Enabled
All end users running Windows 10 or Windows 7 Enterprise.

I have a $folderbrowsermoderndialog1 with an InitialDirectory set to a network path \\server\share\folder. This path is variable depending on a selected combobox.

The app that this is in is deployed out to around 30 users who are using it on a daily basis. I had one user yesterday report that they cant access the share path after clicking to browse for a folder. The computer is running Windows 10 Enterprise.

The screenshot I got from the user looks to shows the folderbrowserdialog, not the modern version. Because of this, its not defaulting to the network path and they are unable to select the folder unless they go into Network > ServerName > Share > Folder manually.

This is what they see (redacted for confidentiality)
folderbrowserdialog.png
folderbrowserdialog.png (16.24 KiB) Viewed 2834 times
If they close the app and restart it, it works again correctly for a bit and then reverts back again. So far I haven't witnessed it myself so I dont know if there is any pattern to it but either way it doesn't make sense.

My understanding is this behavior should only happen if the OS is older than Windows 7.

Any ideas? I cant find anything in my searching thus far.

Thanks.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by mxtrinidad »

This sounds more like a network issue. Do you know the exact error message when the user try to access the shared folder?
In the meantime, we'll be investigating and get back to you soon.
RobBrown
Posts: 13
Last visit: Tue Oct 15, 2019 10:38 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown »

Thanks for the prompt response.

They don't receive any errors that i'm aware of (when I asked they said no), it just opens the folderbrowserdialog to the base "My Computer" location.

If you believe it may be a network connectivity issue, would it be useful to implement a test-path check prior to allowing the dialog to open so we can rule it out?

To provide more details, the application itself will not open if the user is not on the network and can reach the network share. Then they log on (security and logging purposes) and are able to do various functions such as move, copy and rename certain folders within the network share which are otherwise locked down outside of the app.

Although they get this dialog, they are still able to do the other functions to the network share and can still navigate to it via the manual way as outlined in my first post.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by mxtrinidad »

Although we haven't reproduce the issue yet, if there's an issue with the network or even the user credentials, then by default the filebrowser will display the actual user folder list instead of giving an error.

So, for sure you may need to add the necessary code to catch the condition you're experiencing.
:)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra »

RobBrown wrote: Fri Sep 20, 2019 11:28 am Thanks for the prompt response.

They don't receive any errors that i'm aware of (when I asked they said no), it just opens the folderbrowserdialog to the base "My Computer" location.
With this dialog you must test the exisitence of the folder before using it or the problem you are seeing will happen. With shares and network resources the network may become unavailable. This is not a scripting issue and would require that you repair the issue when discovered.
To test the path just use "Test-Path" and report the failure and skip the showing the dialog.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra »

It would be helpful if you posted a simplified version of yuour code so that we can see if there is a coding issue that might cause the path variable to be $null or contain a bad value.
Post the event and the other form code that manages the variable used to set the default.

The FolderBrowserDialog will always default this way when the path is either wrong OR null. This has noting to do with the "modern folder browser" dialog.
RobBrown
Posts: 13
Last visit: Tue Oct 15, 2019 10:38 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown »

Makes sense. The user in question is in the office though and the file share is on the local LAN which is always available. The chance though that its getting disconnected for a moment and reconnecting though is always a possibility. It may be that they are swapping to WiFi and the connection hiccups as well. The share paths available to the end user are static and do not change.

Here is a simplified version of the code.

Code: Select all

$buttonSelect_Click={
	
	if ($comboboxMoveRegion.Text.Length -eq 0)
	{
		$labelMoveResult.ForeColor = 'Red'
		$labelMoveResult.Text = "Error: Select a region first"
		return
	}
	
	switch ($comboboxMoveRegion.Text)
	{
		"1. full name" {
			$MoveRegionPath = "1. folder name"
		}
		"2. full name" {
			$MoveRegionPath = "2. folder name"
		}

	}
	
	$MoveRegionPath = "\\server\folder\$MoveRegionPath"
	$folderbrowsermoderndialog1.InitialDirectory = $MoveRegionPath
	if ($folderbrowsermoderndialog1.ShowDialog() -eq "OK")
	{
		$textboxFolder.Text = $folderbrowsermoderndialog1.SelectedPath
        
        # below this there is other fields modified based on the selected path which is not relevant IMO
    }
}

I will implement the Test-Path check and display an error instead of showing the dialog to see how this goes. I'll get it pushed to the user on Monday and have them test.

Thanks for the help.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra »

Here is a simpler method for doing this:

Code: Select all

$buttonSelect_Click = {
	
	switch ($comboboxMoveRegion.SelectedItem) {
		"1. full name" {
			$MoveRegionPath = "1. folder name"
		}
		"2. full name" {
			$MoveRegionPath = "2. folder name"
		}
		default {
			$labelMoveResult.Text = "Error: Select a region first"
			$labelMoveResult.ForeColor = 'Red'
			return
		}
	}
	
	$MoveRegionPath = "\\server\folder\$MoveRegionPath"
	$folderbrowsermoderndialog1.InitialDirectory = $MoveRegionPath
	if ($folderbrowsermoderndialog1.ShowDialog() -eq "OK") {
		$textboxFolder.Text = $folderbrowsermoderndialog1.SelectedPath
		
		# below this there is other fields modified based on the selected path which is not relevant IMO
	}
}
If you load the ListBox with a collection of simple objects with the display name and the full path as properties then you can just do this.

Code: Select all

$buttonSelect_Click = {
		
	if(Test-Path $comboboxMoveRegion.SelectedItem.FullPath){
		if ($folderbrowsermoderndialog1.ShowDialog() -eq "OK") {
			$folderbrowsermoderndialog1.InitialDirectory = $comboboxMoveRegion.SelectedItem.FullPath
			$textboxFolder.Text = $folderbrowsermoderndialog1.SelectedPath
			
			# below this there is other fields modified based on the selected path which is not relevant IMO
		}
	}else{
		$labelMoveResult.Text = "Error: Path not found"
		$labelMoveResult.ForeColor = 'Red'
	}
}
To load the ComboBox with objects:

Code: Select all

$form1_Load={
	[System.Collections.ArrayList]@($paths = 
		[PsCustomObject]@{ RegionName = 'Name1'; FullPath = '\\server1\folder\folder' }
		[PsCustomObject]@{ RegionName = 'Name2'; FullPath = '\\server2\folder\folder' }
		[PsCustomObject]@{ RegionName = 'Name3'; FullPath = '\\server3\folder\folder' }
	)
	$comboboxMoveRegion.DataSource = $paths
	$comboboxMoveRegion.DisplayMember = 'RegionName'
}
RobBrown
Posts: 13
Last visit: Tue Oct 15, 2019 10:38 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown »

Hi jvierra, thanks for the improved code, this is great! I didn't realize that the combobox could be used in this way.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra »

Yes. All controls with a "DataSource" can be assigned to objects, datatables or data binding controls and then they become the source for the objects being chosen or edited.
This topic is 4 years and 6 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