Solved

networkpath

Posted on 1998-01-28
11
191 Views
Last Modified: 2012-06-27
Hi,

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 ?

Thanks,
Rudi.
0
Comment
Question by:rudi_huysmans
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 32

Expert Comment

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

Author Comment

by:rudi_huysmans
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).
0
 

Author Comment

by:rudi_huysmans
ID: 1179332
Adjusted points to 400
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:inter
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,

Igor

0
 
LVL 1

Expert Comment

by:hustch
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
0
 

Author Comment

by:rudi_huysmans
ID: 1179335
Hello,

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.

0
 
LVL 1

Expert Comment

by:hustch
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.
0
 
LVL 5

Expert Comment

by:inter
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
Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1179338
Sorry the call should be

WNetGetConnection(&local, &remote, &len)
0
 
LVL 2

Accepted Solution

by:
AlFa earned 400 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;
      DWORD dwResult = WNetOpenEnum( RESOURCE_CONNECTED, RESOURCETYPE_DISK,
                                     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);
            continue;
         }

         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;
            }
      }

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

      return fResult;

   }

alain,
0
 

Author Comment

by:rudi_huysmans
ID: 1179340
Thank you, AlFa.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

820 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