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 ?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

To get the full network pathname to a file you have to start with something.  What do you have to start with?
rudi_huysmansAuthor Commented:
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).
rudi_huysmansAuthor Commented:
Adjusted points to 400
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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,


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
rudi_huysmansAuthor Commented:

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.

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.
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
Sorry the call should be

WNetGetConnection(&local, &remote, &len)
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;



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rudi_huysmansAuthor Commented:
Thank you, AlFa.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.