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. How to find out if a file is local or from the network

How to find out if a file is local or from the network

Scheduled Pinned Locked Moved C#
helpcsharpcomsysadmintutorial
3 Posts 2 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.
  • A Offline
    A Offline
    achoi6
    wrote on last edited by
    #1

    Can someone point me in a direction on how to solve this problem? I have to be able to find out if a file I am pointing to is local or not. I can point to a file through the network neighborhood or through a networked drive. I think finding out if the file was accessed through the network neighborhood would not be a problem, its when I map a network drive. Once the drive is mapped, it is given a drive letter like any other local drive. Help would be much appreciated. PS. This seems promising... http://www.codeproject.com/csharp/mapnetdrive.asp[^] My idea was to try to unmap the drive and if my attempt fails, the drive must be local. The problem is, that if I unmap a drive with a username:pw, I have to remap it with the same username:pw which I may not have. For the network neighborhood, Does checking the root of a file work? ex. \\NAME\c$

    T 1 Reply Last reply
    0
    • A achoi6

      Can someone point me in a direction on how to solve this problem? I have to be able to find out if a file I am pointing to is local or not. I can point to a file through the network neighborhood or through a networked drive. I think finding out if the file was accessed through the network neighborhood would not be a problem, its when I map a network drive. Once the drive is mapped, it is given a drive letter like any other local drive. Help would be much appreciated. PS. This seems promising... http://www.codeproject.com/csharp/mapnetdrive.asp[^] My idea was to try to unmap the drive and if my attempt fails, the drive must be local. The problem is, that if I unmap a drive with a username:pw, I have to remap it with the same username:pw which I may not have. For the network neighborhood, Does checking the root of a file work? ex. \\NAME\c$

      T Offline
      T Offline
      techieboi
      wrote on last edited by
      #2

      One possible solution is to use the WIN32 API function GetDriveType. By passing in the drive as a string, the function will return the drive type as shown below. int nDriveType = GetDriveType("Z:\\"); if (nDriveType == DRIVE_REMOTE) MessageBox(NULL, "Network Drive", "Network Drive", MB_OK | MB_ICONINFORMATION); Hope this helps.

      A 1 Reply Last reply
      0
      • T techieboi

        One possible solution is to use the WIN32 API function GetDriveType. By passing in the drive as a string, the function will return the drive type as shown below. int nDriveType = GetDriveType("Z:\\"); if (nDriveType == DRIVE_REMOTE) MessageBox(NULL, "Network Drive", "Network Drive", MB_OK | MB_ICONINFORMATION); Hope this helps.

        A Offline
        A Offline
        achoi6
        wrote on last edited by
        #3

        Yup that should do it! I actually just found that as well. Much thanks. I also found some more usefull functions in mpr.dll http://computer.programming-in.net/articles/art9-2.asp?lib=mpr.dll[^]

        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