Getting network drives names issue
-
I think what he means is that
d.DriveType == DriveType.Network
is never true under Windows 7, while it is under Windows XP. If you look, the OP does say that the code works under XP...Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
I have checked your code but it works in Windows 7 also!
Hi Goutam Patra, It does not work in my envoirment. i can see the drives in windowns explorer , but not with my code. And if i try to read a file from a directory in network drive(i have read permissions) , im getting:
Could not find a part of the path \\network\dir
-
I have checked your code but it works in Windows 7 also!
Goutam Patra wrote:
I have checked your code but it works in Windows 7 also!
are you sure you are able to see Network Drive as well as Local Drive by using OP codes.
-
Dear all, Im using this code to get the names of shared network drives in my computer:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.DriveType == DriveType.Network)
{
Response.Write(d.Name);
}
}In win xp this works fine, but in windows7 i can only see the local drives. Any idea why ? and how to solve this? Thanks in advance.
Try using WMI instead. The following code should get a list of network drives:
public static List<string> FindNetworkDrives()
{
List<string> networkDrives = new List<string>();
SelectQuery query = new SelectQuery("select name from win32_logicaldisk where drivetype=4");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject obj in searcher.Get())
{
networkDrives.Add(obj["Name"]);
}
return networkDrives;
}I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Goutam Patra wrote:
I have checked your code but it works in Windows 7 also!
are you sure you are able to see Network Drive as well as Local Drive by using OP codes.
Absolutely.
-
Try using WMI instead. The following code should get a list of network drives:
public static List<string> FindNetworkDrives()
{
List<string> networkDrives = new List<string>();
SelectQuery query = new SelectQuery("select name from win32_logicaldisk where drivetype=4");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject obj in searcher.Get())
{
networkDrives.Add(obj["Name"]);
}
return networkDrives;
}I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Dear all, Im using this code to get the names of shared network drives in my computer:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.DriveType == DriveType.Network)
{
Response.Write(d.Name);
}
}In win xp this works fine, but in windows7 i can only see the local drives. Any idea why ? and how to solve this? Thanks in advance.
My guess would be you have a problem with permissions on your Win7 machine; nothing wrong with all the code you tried. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
My guess would be you have a problem with permissions on your Win7 machine; nothing wrong with all the code you tried. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I think also it had to do with permissions, but dont understand how, i tried to get files via asp.net fileupload control from those network drives, no problems...but when i try to read the same file with
StreamReader
im getting again that error.Uhhh, what? How does a web app fit into all this?? There's something you're not telling us that's affecting this problem or causing it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Dear all, Im using this code to get the names of shared network drives in my computer:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.DriveType == DriveType.Network)
{
Response.Write(d.Name);
}
}In win xp this works fine, but in windows7 i can only see the local drives. Any idea why ? and how to solve this? Thanks in advance.
Priya Prk wrote:
but in windows7 i can only see the local drives.
1. Create a sample class/project console application that ONLY does this code and prints the results via System.Console. 2. Open a console window in Windows 7. 3. Run that app. 4. If it does NOT display the network drives then remove the condition check and run again. Post that class, the complete class, and the output if it does not report the drives. If it does report the drives then it means the context of your original app, not the code, is the source of your problem.