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.
RobBrown
Posts: 13
Joined: Fri Sep 20, 2019 8:40 am

folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown » Fri Sep 20, 2019 9:00 am

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 402 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
Site Admin
Posts: 351
Joined: Sun Mar 03, 2013 12:42 pm

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by mxtrinidad » Fri Sep 20, 2019 9:11 am

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
Joined: Fri Sep 20, 2019 8:40 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown » 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.

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
Site Admin
Posts: 351
Joined: Sun Mar 03, 2013 12:42 pm

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by mxtrinidad » Fri Sep 20, 2019 11:33 am

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.
:)

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra » Fri Sep 20, 2019 11:57 am

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.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra » Fri Sep 20, 2019 12:05 pm

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
Joined: Fri Sep 20, 2019 8:40 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown » Fri Sep 20, 2019 12:55 pm

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.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra » Fri Sep 20, 2019 1:38 pm

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
Joined: Fri Sep 20, 2019 8:40 am

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by RobBrown » Mon Sep 23, 2019 7:41 am

Hi jvierra, thanks for the improved code, this is great! I didn't realize that the combobox could be used in this way.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: folderbrowsermoderndialog reverting to non modern on Win 10

Post by jvierra » Mon Sep 23, 2019 10:33 am

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.

Post Reply