[Webinar] Streamline your web hosting managementRegister Today



Posted on 1998-01-28
Medium Priority
Last Modified: 2012-06-27

I'm trying to store the full network path of a file in a shared directory network into a database, so that other users using the same database can call up this documet from anywhere in the network. I suppose there is a Windows API to retrieve the full network path a file. Does anybody know which one and how to use it ?

Question by:rudi_huysmans
  • 4
  • 3
  • 2
  • +2
LVL 32

Expert Comment

ID: 1179330
To get the full network pathname to a file you have to start with something.  What do you have to start with?

Author Comment

ID: 1179331
I currently have the complete drivename + path + filename. This might also be on a networkdrive using a mapped directory. (ex. C:\My Documents\document.doc or L:\docs\document.doc).

Author Comment

ID: 1179332
Adjusted points to 400
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Expert Comment

ID: 1179333
I feel that I know the answer but I should ask some questions:

1 - What is your OS?
2 - Is the following explains what you want to do:
    You have a document server A (computername) and there is a file on that (e.g. c:\dir1\dir2\test.doc'). There are other computers in the network named B, C, ...etc. You share the c:\dir1\dir2 as for example 'AShare'. Say all the other computers maps it as for example 'F:'. Now:

i - Do you want to store 'F:\test.doc' in database and from it restore c:\dir1\dir2\test.doc?
ii- Or you want to store 'c:\dir1\dir2\test.doc' so that you retreive 'F:\test.doc'

Please notify,



Expert Comment

ID: 1179334
On Windows NT you can use WNetGetUniversalName

DWORD WNetGetUniversalName(

    LPCTSTR  lpLocalPath,      // address of drive-based path for a network resource
    DWORD  dwInfoLevel,      // specifies form of universal name to be obtained
    LPVOID  lpBuffer,      // address of buffer that receives universal name data structure
    LPDWORD  lpBufferSize       // address of variable that specifies size of buffer

See the Win32

Author Comment

ID: 1179335

thank you for your answer but the operating system I'm programming for is Windows '95.
I did try the function (you never now with MS) but it didn't work in '95.

I'll give some more details about the question:
OS: WIN '95
What I'm trying to do is something like this:
There's a document on the server in \dir1\documents\doc1.txt.
When a user selects this file it would probably look to him like L:\documents\doc1.txt. L is actually mapped to the directory on the server. This has to be translated into \\ServerName\documents\doc1.txt assuming that the server is named ServerName.
I did find such a function in WordBasic named fileInfo. But I can't rely on the fact that Word is installed to used this.


Expert Comment

ID: 1179336
I know, it doesn't work under Windows 95
I'll try to find a solution for 95, but I won't have time before at the end ot this week.

Expert Comment

ID: 1179337
Dear rudi_huysmans,

The function that both works on NT and 95 is WNetGetConnection exported from mpr.dll(when you search for it from findfiles containing WNetGetConnection it is in system directory for win95), here is the script to retreive the actual network path of a device:

  char remote[255], local[255];
  DWORD len;

  strcpy(remote, "L:");
  len = sizeof(remote);
  if ((WNetGetConnection(local, remote, len) == NO_ERROR) {
     // the remote now contains e.g. \\servername\dir1\dir2
     // so just append the path after L: e.g. \documents

Tell me if it helps

Expert Comment

ID: 1179338
Sorry the call should be

WNetGetConnection(&local, &remote, &len)

Accepted Solution

AlFa earned 1600 total points
ID: 1179339
Perhaps Ms has the answer

The functionality provided by WNetGetUniversalName can be implemented using the Win32 network enumeration functions WNetOpenEnum and WNetEnumResource. Here is an example of how to use these functions to implement similar functionality:

   #include <windows.h>
   #include <stdio.h>

   // Function Name:  GetUniversalName
   // Parameters:     szUniv  - contains the UNC equivalent of szDrive
   //                           upon completion
   //                 szDrive - contains a drive based path
   // Return value:   TRUE if successful, otherwise FALSE
   // Comments:       This function assumes that szDrive contains a
   //                 valid drive based path.
   //                 For simplicity, this code assumes szUniv points
   //                 to a buffer large enough to accommodate the UNC
   //                 equivalent of szDrive.

   BOOL GetUniversalName( char szUniv[], char szDrive[] )
      // get the local drive letter
      char chLocal = toupper( szDrive[0] );

      // cursory validation
      if ( chLocal < 'A' || chLocal > 'Z' )
         return FALSE;

      if ( szDrive[1] != ':' || szDrive[2] != '\\' )
         return FALSE;

      HANDLE hEnum;
                                     0, NULL, &hEnum );

      if ( dwResult != NO_ERROR )
         return FALSE;

      // request all available entries
      const int    c_cEntries   = 0xFFFFFFFF;
      // start with a reasonable buffer size
      DWORD        cbBuffer     = 50 * sizeof( NETRESOURCE );
      NETRESOURCE *pNetResource = (NETRESOURCE*) malloc( cbBuffer );

      BOOL fResult = FALSE;

      while ( TRUE )
         DWORD dwSize   = cbBuffer,
               cEntries = c_cEntries;

         dwResult = WNetEnumResource( hEnum, &cEntries, pNetResource,
                                      &dwSize );

         if ( dwResult == ERROR_MORE_DATA )
            // the buffer was too small, enlarge
            cbBuffer = dwSize;
            pNetResource = (NETRESOURCE*) realloc(pNetResource, cbBuffer);

         if ( dwResult != NO_ERROR )
            goto done;

         // search for the specified drive letter
         for ( int i = 0; i < (int) cEntries; i++ )
            if ( pNetResource[i].lpLocalName &&
                 chLocal == toupper(pNetResource[i].lpLocalName[0]) )
               // match
               fResult = TRUE;

               // build a UNC name
               strcpy( szUniv, pNetResource[i].lpRemoteName );
               strcat( szUniv, szDrive + 2 );
               _strupr( szUniv );
               goto done;

      // cleanup
      WNetCloseEnum( hEnum );
      free( pNetResource );

      return fResult;



Author Comment

ID: 1179340
Thank you, AlFa.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

607 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