Skip to main content

JFilechooser doesn't display client drive content with remote desktop

No replies
christiaan_se
Offline
Joined: 2006-07-13
Points: 0

Hi,
I am posting this here since it may be helpful to others as well. In the following scenario the JFileChooser doesn't display the content of a local drive:
- Deploy an application with a JFileChooser on Windows server and enable access via remote desktop;
- Start remote desktop connection from client to server and enable local (client) disk access
- JFileChooser will display local (C) drive;
- Double clicking on local c-drive will show an empty list instead of the drive content;

To fix this, create a subclass of FileSystemView and override:

@Override
public File[] getFiles(File dir, boolean useFileHiding) {
File[] result = super.getFiles(dir, useFileHiding);
if (dir != null && (result == null || result.length == 0)
&& dir.getPath().startsWith("\\\\")) {
//When dir is a folder on a client machine, while the application
//is running with remote desktop,
//ShellFolder (which is a UNC path) is not returning the content of the folder
//Creating a new file will return the contents
File newDir = new File(dir.getAbsolutePath());
result = newDir.listFiles();
}
return result;
}

Next, call setFileSystemView() on your JFileChooser to pass on the custom FileSystemView.

Note, I reported this with Sun a couple of weeks ago, but didn't get any reaction so far.

kind regards,
Christiaan