In my WPF app the user needs to select a folder, which path is in the company network. I use the System.Windows.Forms.FolderBrowserDialog and the following code gets executed on a button click event:
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = "\\\\company.net\\data\\_Confidential";
DialogResult result = fbd.ShowDialog();
When the FolderBrowserDialog opens, the system automatically scans for other network devices and that causes the following problem:
The network tree gets filled with other devices and causes my SelectedPath to scroll away. This is pretty annoying when a user starts searching for a special subfolder, because he has to scroll down or his selection clicks can hit a newly added device (lost focus).
How can i avoid this problem?
Thoughts:
Can I extend/overwrite the System.Environment.SpecialFolder Enum and
set fbd.RootFolder = System.Environment.SpecialFolder.MySepcialNetworkPath;
Should I access the network folder with another dialog/control?
Should I remove the "Browse..." Button in my View and instead scan the whole \\\\company.net\\data\\_Confidential path and provide a combobox/other selection control(e.g. own subfolder-tree)?
The FolderBrowserDialog is 'adopting' your PC settings depending on how your Network Discovery is configured on your PC/network. By doing so your folder browsing experience will be consistent over other applications.
Although what you see is default behavior of the FolderBrowserDialog, you may also look at this: https://stackoverflow.com/a/15440926/5793786 Solved an issue somewhat similar to yours #Frank
While I was searching for the same problem I came across this thread:
How to use OpenFileDialog to select a folder?
Where the user uses a "CommonOpenFileDialog" available in the Nuget Package "WindowsAPICodePack-Shell".
This solved my issue, though it uses the OpenFileDialog interface.
Then the network drive can just be browsed.
Related
I wrote an image viewer application in C# to replace Windows 7 Photo Viewer which does not have the one feature I needed, which was to set the ratings and keywords directly from the view screen and not by opening some less user-friendly property pages. It works Ok for my need, but I wanted to improve it with a slideshow.
With Windows 7 Photo Viewer, what I usually did was I set the keywords of the picture, I used Windows Explorer "organize by" feature, clicked one keyword, double-clicked one file and run the slideshow from there.
But when I double-click a file from the keyword-"organized" folder in Windows Explorer, all my app gets is the command-line argument, i.e. the full name of the file.
I could admit running my slideshow from there, using System.IO.Path.GetDirectoryName to get all files from the folder, but I find it lacks a certain "panache", don't you think?
I am not asking for code here. But could someone just point me in the right direction, please? I don't know what WindowsExplorer actually gives PhotoViewer that allows it to only show the required files. And why.
Thanks for any help.
When you use Organize by feature of Windows Explorer it creates special virtual folder. And this folder contains files with selected keyword only. Mechanism of opening of PhotoViewer differs from standard way. If you open HKEY_CLASSES_ROOT\jpegfile\shell\open registry key you will see that where is DropTarget subkey. It means when you double-clicked the file shell creates inproc com server with CLSID from DropTarget subkey and pass virtual path of image to IDropTarget instance. So PhotoViewer work with list of virtual objects instead of physical directory.
I have a openfiledialog in my application. I do not set the initial directory and user can navigate to open file and import it to the application (for example imports excel file from C:\ Test location). Next time, when user wants to open another file, system (by default, since initial directory is not set) remember the previous location and openfiledialog opens in that directory (C:\ Test). Is there anyway to retrieve the path that openfiledialog opens? I am sorry if I couldn't explain my problem well and thanks for the help.
Registry is hard to handle, I would suggest that you use Application Properties instead.
I have a C# winforms application that I am using. I have a "browse output folder" button that takes the user to a specific path on a network drive for our local systems.
However, I have been getting these weird exceptions from Explorer.exe where it crashes for no particular reason with no real error message. This occurs when the folder opens up properly and sits for a while, it will open a message saying that it "has stopped working" and asks me to close it. This issue is very repeatable.
My best guess at the issue is that it is a network related problem. The network has been known to be glitchy occasionally (goes up/down briefly fairly often). Could this cause the problem?
The code I use is (I do typically check that the folder path is valid):
string Path = "\\\\serverPath\\data\\My Folder\\";
System.Diagnostics.Process.Start("Explorer.exe", Path);
Basic question summary: Am I making this call to Explorer.exe improperly / is there a better/safer way of doing this to avoid this problem?
EDIT: OR is as I expected and is just a windows bug that I'm going to have to deal with... =(
If you want an alternative way of opening the folder try using SHOpenFolderAndSelectItems. To open a folder I think you can use the same PCITEMIDLIST as the parent and the selection:
SHOpenFolderAndSelectItems(folder, 1, &folder, 0);
I'm supporting an old version of a C# application, running on .NET 3.5. We've found an issue with the FolderBrowserDialog on Windows Vista (either 32 or 64-bit).
Basically what happened is that the dialog would appear, but only the root Desktop node would be shown, not even able to expand it to show anything else. Obviously, that's impossible to use.
After a huge amount of trial and error I eventually managed to get something useable, by setting the RootFolder property before the rest of the setup:
FolderBrowserDialog browsePath = new FolderBrowserDialog();
browsePath.RootFolder = Environment.SpecialFolder.MyComputer;
browsePath.SelectedPath = this.textBoxTo.Text;
browsePath.Description = TextResources.OutputTargetCaption;
browsePath.ShowNewFolderButton = true;
if(browsePath.ShowDialog(this) == DialogResult.OK)
{
this.textBoxTo.Text = UpdateLocation(browsePath.SelectedPath);
}
This almost works; however, I've got the bizarre issue that then the SelectedPath (by definition the contents of textBoxTo) is a path to within the current user's home directory, it won't automatically browse to that path, instead just showing the My Computer node expanded to one level. It's perfectly fine for any other path.
I'm sure your first guess would be a permissions issue, as was my intuition. It doesn't appear to be, this issue occurs running normally and as an Administrator, for both standard and Administrator accounts. It's a clean install, of course, no weird permissions or anything.
This is pretty annoying when all of our defaults are within the current user's directory!
Note: This only happens within the application; it's not reproducible with a small test application, as far as I've seen.
Any ideas on what could be causing this?
Update: Screenies:
This is the behaviour I want (obtainted from a little test app)
This is what I get with the default property
This is what I get by setting the root to My Computer
Note: The last image had the same SelectedPath set as the expected image...
I had a similar problem. In Windows Vista and Windows 7 the following code:
browsePath.RootFolder = Environment.SpecialFolder.MyComputer;
returns the Desktop. If you look in Windows Explorer, the root of the tree is Desktop, not My Computer like it was in Windows XP.
To solve this problem use this instead:
browsePath.RootFolder = #"C:\";
Every Windows computer has a C:\ drive, so this will solve your problem.
I hope this helps you.
If you're only accessing the users private folders, use
browsePath.RootFolder = Environment.SpecialFolder.Personal
Only the specified folder and any subfolders that are beneath it will
appear in the dialog box and be selectable. The SelectedPath property,
along with RootFolder, determines what the selected folder will be
when the dialog box is displayed, as long as SelectedPath is an
absolute path that is a subfolder of RootFolder (or more accurately,
points to a subfolder of the shell namespace represented by
RootFolder).
In short, you can not input someones private folder as a startup selectedPath unless RootFolder is inside the current users private folder already.
For details, see: http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.rootfolder.aspx
VB.NET code
Dim fdb As New FolderBrowserDialog
With fdb
'.RootFolder = Environment.SpecialFolder.MyComputer
'this folder don't exists in vista, the my computer folder was renamed to computer (in spanish "mi pc" to "equipo")
'try with another initial folder
.RootFolder = Environment.SpecialFolder.Desktop
'You can set the desktop as home directory because users typically already have shortcuts or the left side menu to navigate
Dim dr As DialogResult = .ShowDialog
If _
dr = DialogResult.OK Or _
dr = DialogResult.Yes Then _
If IO.Directory.Exists(.SelectedPath) = True Then _
Me.textBoxTo.Text = UpdateLocation(.SelectedPath)
End With
basically, try another directory and make sure the chosen directory exists.
if you're still having problems, is probably due to some fault in the system.
In my application I have two places where the user needs to select a file. In both cases, the files are in different directories, but they are generally the same between runs.
The OpenFileDialog appears to be defaulting to the last directory used, but this is useless to me since it is almost always the wrong folder, and I end up alternating between the two folders. What I would like is to somehow have the first dialog remember the path that was used the last time it was opened, and the second to remember its own path as well.
Example: Path A is C:\foo\bar\something\x.dll, Path B is C:\foo\baz\whatever\y.xml
Dialog a opens and I select A, then later dialog b opens(defaulted to A) and I have to navigate back and up to B.
When I open the app again dialog a opens (defaulted to B) and I have to navigate back up to A again.
I would like to avoid all of this extra navigation by remembering the paths separately. Is there a good way to do that?
When you open each dialog, just set the dialog's InitialDirectory property to the folder that was last used for that dialog.
Granted, this will require saving the directory for each dialog, but it will provide the behavior you are looking to achieve.