Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

detect network (shared) drive using C#

Posted on 2006-10-24
3
Medium Priority
?
1,009 Views
Last Modified: 2010-05-18
How can I determine if a drive is mapped or local, using C#? I am using .NET Framework 1.1 with VS.NET 2003.

thanks
guid
0
Comment
Question by:guidway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Expert1701 earned 2000 total points
ID: 17805617
On version 1.1 of the Framework, you can use:

  static bool IsNetworkDrive(char driveLetter)
  {
    const int NetworkDrive = 4;

    System.Management.ObjectQuery query = new System.Management.ObjectQuery("SELECT * FROM Win32_LogicalDisk");
    System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
    System.Management.ManagementObjectCollection drives = searcher.Get();

    foreach (System.Management.ManagementBaseObject drive in drives)
      if (drive.Properties["DeviceID"].Value.ToString()[0] == driveLetter)
        return Convert.ToInt32(drive.Properties["DriveType"].Value) == NetworkDrive;

    throw new ArgumentException();
  }

And when you upgrade to version 2.0:

  static bool IsNetworkDrive(char driveLetter)
  {
    foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
      if (drive.ToString()[0] == driveLetter)
        return drive.DriveType == System.IO.DriveType.Network;

    throw new ArgumentException();
  }
0
 
LVL 12

Author Comment

by:guidway
ID: 17812179
Excellent! That's more than I expected, but information I needed ( we are about to upgrade to 2.0).

Increasing to 500.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17813345
Thank you, guidway!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question