Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting network drives names issue

Getting network drives names issue

Scheduled Pinned Locked Moved C#
csharpsysadminhelptutorialquestion
14 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Priya Prk
    wrote on last edited by
    #1

    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.

    R G P L J 5 Replies Last reply
    0
    • P Priya Prk

      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.

      R Offline
      R Offline
      RaviRanjanKr
      wrote on last edited by
      #2

      Priya Prk wrote:

      In win xp this works fine, but in windows7 i can only see the local drives.

      how that is possible to see the local drives after using given code. It will display only when you will use DriveType.Fixed [as I know] Check your code it only display Network Drives Name not LocalDrives Name because Response.Write(d.Name) only works and print the Name of Drives when DriveType will equals to DriveType.Network Take a look you've applied condition.

      Priya Prk wrote:

      if (d.DriveType == DriveType.Network) { Response.Write(d.Name); }

      modified on Friday, January 14, 2011 5:19 AM

      OriginalGriffO 1 Reply Last reply
      0
      • R RaviRanjanKr

        Priya Prk wrote:

        In win xp this works fine, but in windows7 i can only see the local drives.

        how that is possible to see the local drives after using given code. It will display only when you will use DriveType.Fixed [as I know] Check your code it only display Network Drives Name not LocalDrives Name because Response.Write(d.Name) only works and print the Name of Drives when DriveType will equals to DriveType.Network Take a look you've applied condition.

        Priya Prk wrote:

        if (d.DriveType == DriveType.Network) { Response.Write(d.Name); }

        modified on Friday, January 14, 2011 5:19 AM

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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 no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        P 1 Reply Last reply
        0
        • P Priya Prk

          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.

          G Offline
          G Offline
          Goutam Patra
          wrote on last edited by
          #4

          I have checked your code but it works in Windows 7 also!

          P R 2 Replies Last reply
          0
          • OriginalGriffO OriginalGriff

            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.

            P Offline
            P Offline
            Priya Prk
            wrote on last edited by
            #5

            Hi all, My bad. OriginaGriff is right.. DriveType.Network is never true.

            1 Reply Last reply
            0
            • G Goutam Patra

              I have checked your code but it works in Windows 7 also!

              P Offline
              P Offline
              Priya Prk
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • G Goutam Patra

                I have checked your code but it works in Windows 7 also!

                R Offline
                R Offline
                RaviRanjanKr
                wrote on last edited by
                #7

                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.

                G 1 Reply Last reply
                0
                • P Priya Prk

                  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.

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  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

                  My blog | My articles | MoXAML PowerToys | Onyx

                  P 1 Reply Last reply
                  0
                  • R RaviRanjanKr

                    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.

                    G Offline
                    G Offline
                    Goutam Patra
                    wrote on last edited by
                    #9

                    Absolutely.

                    1 Reply Last reply
                    0
                    • P Pete OHanlon

                      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

                      My blog | My articles | MoXAML PowerToys | Onyx

                      P Offline
                      P Offline
                      Priya Prk
                      wrote on last edited by
                      #10

                      Hi Pete O'Hanlon, I did try your code, but unfortunately still no results.

                      1 Reply Last reply
                      0
                      • P Priya Prk

                        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.

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        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.

                        P 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          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.

                          P Offline
                          P Offline
                          Priya Prk
                          wrote on last edited by
                          #12

                          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.

                          D 1 Reply Last reply
                          0
                          • P Priya Prk

                            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.

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            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

                            1 Reply Last reply
                            0
                            • P Priya Prk

                              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.

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #14

                              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.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups