 |
|
|
 |
|
 |
I need to simply get a list of available network shares using VB.NET. How can I do this? This piece of code is soooo close - but it only returns one item the user clicks on. I want to build my own list.
|
|
|
|
 |
|
 |
Thanks Jatin,
I wasn't sure how to do this, and your example got me moving right along.
With your link, I was able to convert your code to C# easily, which resulted in this slimmed down version:
using (FolderBrowserDialog dlg = new FolderBrowserDialog()) {
Type type = dlg.GetType();
System.Reflection.FieldInfo fieldInfo = type.GetField("rootFolder", BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(dlg, (Environment.SpecialFolder)18);
dlg.Description = "Select or Create Folder";
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.SelectedPath);
}
}
After spending a few moments with how your code was being used, I noticed that we can accomplish the same thing without reflection (unless you just like using it):
using (FolderBrowserDialog dlg = new FolderBrowserDialog()) {
dlg.RootFolder = (Environment.SpecialFolder)18;
dlg.Description = "Select or Create Folder";
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.SelectedPath);
}
}
Next, I went a step further and noticed that I can see *both* my PC's directory structure along with the network folders if I simply point the RootFolder to the Desktop:
using (FolderBrowserDialog dlg = new FolderBrowserDialog()) {
dlg.RootFolder = Environment.SpecialFolder.Desktop;
dlg.Description = "Select or Create Folder";
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.SelectedPath);
}
}
I could not have done this without your help to get me started!
Thank you, and I hope others get some use out of my post.
Kind Regards,
Joe Pool
modified on Monday, July 20, 2009 2:21 PM
|
|
|
|
 |
|
 |
I tried:
fieldInfo.SetValue(dlg, (Environment.SpecialFolder)18);
and I got an InvalidEnumArgumentException:
"The value of argument 'value'(18) is invalid for Enum type 'SpecialFolder'"
Then I tried:
dlg.RootFolder = Environment.SpecialFolder.
but sharedfolder is no one of the options.
Tom
|
|
|
|
 |
|
 |
Hi Tom,
My code was written with Visual Studio 2005. The author of this post used Visual Studio 2008, and the Network Folders may not be available in later versions of the framework.
Right click on SpecialFolders in your version of Visual Studio and select "Go To Definition". This should take you to a list of Special Folder enumerations (from metadata) that are available on your PC.
You mentioned that you tried setting dlg.RootFolder = Environment.SpecialFolder. This will not work because the FolderBrowserDialog method RootFolder accepts a Special Folder value, not the definition of a Special Folder type.
All else aside, if instead you use dlg.RootFolder = Environment.SpecialFolder.Desktop; - does your FolderBrowserDialog show your network folders?
|
|
|
|
 |
|
 |
I am using Visual Studio 2005 version 8.0.50727.762 running on XP 5.1.2600. Network folders is not among the enumeration list shown by FolderBrowserDialog.
|
|
|
|
 |
|
 |
It might be a Windows preference - that is, something that depends on options selected when Windows was installed.
I noticed the enumeration was not on my work PC, but it is on my home PC, both of which are Windows XP Pro with SP3.
I'm not sure what the difference is or why it is available on one version but not the other.
|
|
|
|
 |
|
 |
private void button1_Click(object sender, EventArgs e)
{
folderName = GetNetworkFolders(folderBrowserDialog1);
}
private string GetNetworkFolders(FolderBrowserDialog oFolderBrowserDialog)
{
Type type = oFolderBrowserDialog.GetType();
FieldInfo fieldInfo = type.GetField("rootFolder", BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(oFolderBrowserDialog,18);
if (oFolderBrowserDialog.ShowDialog() == DialogResult.OK)
{
return oFolderBrowserDialog.SelectedPath.ToString();
}
else
{
return "";
}
}
|
|
|
|
 |
|
 |
Thank you so very much! You're a genius!
|
|
|
|
 |
|
 |
do you have a code for browsing network folders using Visula Basic 6?
|
|
|
|
 |
|
 |
How could I use this to select my connection string location on another networked computer?
|
|
|
|
 |
|
 |
Hi,
Saw your article, i have an extended question on it. In your article you showed how to show the network folders.
Is there is any way that we can just limit it to one specific computer(preferable the localhost)?
thanks
|
|
|
|
 |
|
 |
Unfortunately, that's not possible using the folder browser dialog. However, you can use a 3rd party control such as FolderView control from http://www.ssware.com/megapack.htm
|
|
|
|
 |
|
 |
Hello,
Is this possible to get the shared folder's local path using c#.
We are designing desktop application and needs to access database on a network machine shared folder.
So it is required to get a database file's local path to connect to it.
Thanks in advance
Jay.
|
|
|
|
 |
|
 |
yes, its possible....and you can access it through network machine shared folder
but which database you want to access ?
is it MS Access DB ?
|
|
|
|
 |
|
 |
Thanks for reply,
We have a firebird database file.
That file is on the shared folder of a network machine.
For configuring the firebird file at client application on another machine, we need to get the local path of database file.
Best Regards,
Jay.
|
|
|
|
 |
|
 |
can anybody tell how to create the open Folder dialog box in web application like browsing file dialog box.
Geeth
|
|
|
|
 |
|
 |
you have to create it manually, but you can browse Server Files and folder only....
|
|
|
|
 |
|
 |
Hai Jatin Prajapati,
Thanks for your suggestion on this.
I already read your previous article on opening Network folders and its working in win application.
i have been trying and searching the ways to find out the solution in web application but still i can't get correct solution.
In my application i need to provide a facility to client for selecting
folders either his own system or any other system through LAN for storing some files.
if you know anything about that please send me the required information.
Thanks in advance.
|
|
|
|
 |
|
 |
i think we can not browse local system files and folders using web application.
but you can try this one
http://www.visualwebgui.com/[^]
may be, they will give facility...
|
|
|
|
 |
|
 |
thanks for your response.
i found one article that using only javascript for showing the floder dialog box.
but its not working in my application its showing a pop up box like activex control not started or loaded.
can you check this site and tell me your openion.
http://www.tek-tips.com/faqs.cfm?fid=5201
|
|
|
|
 |
|
 |
Came across your code and was immediately pleased as its solved a problem I've been working on, however the SetValue statement is proving a problem.
The following line (Visual Studio 2003) as per the example code:
fieldInfo.SetValue(oFolderBrowserDialog, DirectCast(18, Environment.SpecialFolder))
is throwing the compile error: 'DirectCast' operand must have a reference type, but 'EmXP_Toolbar.fDrives.sysRoot' is a value type.
I am struggling to rectify this and any help would be appreciated - is this a limitation of 2003 ? Or am I missing something here.
Many thanks,
Tim.
|
|
|
|
 |
|
 |
I want to use this to simply select a computer.
|
|
|
|
 |
|
 |
Here is the code to do that,
Dim objFdialog As New FolderBrowserDialog
objFdialog.RootFolder = Environment.SpecialFolder.MyComputer
objFdialog.ShowDialog()
|
|
|
|
 |
|
 |
I didn't explain myself well enough.
I want to use the dialog to select another computer on the network.
Then I will use my WMI query code to investigate that computer.
The browser lets me click on drives within a computer, but the "OK" is disabled when I have clicked on the computer itself.
Can you just select a computer from the network neighborhood with this dialogbox ?
Mr. Jiggs
|
|
|
|
 |