Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use network file

Status
Not open for further replies.

amerifax

Technical User
Dec 28, 2006
37
0
0
We are trying to use a field across the network. Rather than using a mapped network drive we would like to use the network path to the file.

When we use the following path:

use \\heather\c\file\dbv\Per_dil excl

We get this error:

Invalid file name.

Do you see any problems with this?

Bob
 
Is Heather a File server or Users Computer ?

If Users Computer, do the people have rights to the directory in question.

the \c\ Should that be \c$\
or
the name of the drive partition \\Heather\Drivec\


David W. Grewe Dave
 
Yes and no. We are running a peer-to-peer network. The workgroup is Amerifax the computer the file is copying from is Heather and the computer it is copying to is Aux. The directory and drive are shared. I get an invalid file name error when trying to call it. I can navigate to file just fine. So access is OK.

Bob
 
Can you access the table and open it when you do
USE ? from the command line

If you can try
? DBF()
and see what the path is




David W. Grewe Dave
 
No if I map a network letter to the drive it will work. But when I type the actual network path which is:

\\heather\c\file\dbv\per_dil

I get the error invalid file name and I know that is not the case.

Bob
 
Do not know why it is doing it, Here is a Function I wrote to play with Drive letter & UNC's.
You can Map a drive, Remove a drive, List Drive letters and list Server mapped to a drive.

Try passing the parameters to map a drive and store the Drive letter to a memvar, then before you terminiate the program remove the drive by passing it the memvar.

I wrote it for a FOXPRO app but it should work in dBase.
Code:
*/***************************************************************************
*# WScript.Network.Information
*/Program   : UNC_INFO.PRG
*/System    : library
*/Purpose   : Take a UNC path / Drive Letter and returns the drive letter / UNC Path
*/Syntax    : string = unc_info(Action,Value)
*/Parameter : action - string - Type of Action to perform
*/          : Value  - string - A UNC name or a Drive Letter to act on
*/Returns   : string - drive letter or UNC for the users computer
*/Defaults  : none
*/Requires  : none
*/Changes   : none
*/Calls     : none
*/Version   : 
*/Dated     : 01/10/2005
*/Written By: David Grewe
*/***************************************************************************
*&Utility
* 
* Action Values - Network
* L=Drive Letter - Value format needs to be \\server\volume
* M=Map Drive    - Value format needs to be \\server\volume
* R=Remove Map   - Value format needs to be "D:"
* S=Server UNC   - Value format needs to be "D:"
*
* Action Values - Computer
* N=Computer Name - Value not required
* D=Domain Name   - Value not required
* U=User Name     - Value not required
*
*/***************************************************************************
*/ Record Of Change
*/ 
*/***************************************************************************
FUNCTION UNC_INFO
LPARAMETERS pcAction,pcValue
IF	PARAMETERS()<1 OR VARTYPE(pcAction)<>"C" OR EMPTY(pcAction)
	RETURN ''
ENDIF
IF	PARAMETERS()<2 OR VARTYPE(pcValue)<>"C" OR EMPTY(pcValue)
	RETURN ''
ENDIF
*
LOCAL WshNetwork,oDrives,i,lcValue,lcRetVal
STORE ALLTRIM(UPPER(pcValue)) TO pcValue,lcValue
STORE '' TO lcRetVal
*
* Get an array of Drive letters used and the UNC's assigned to them
*
WshNetwork=createobject("WScript.Network")
oDrives=WshNetwork.EnumNetworkDrives          &&NOTE:  This array is 0 based
*
DO CASE 
CASE pcAction = "L"   && drive letter for UNC - 
	*
	* pcValue should be "\\Server\volume" format
	* Check to see if UNC is in the array
	*
	FOR i=0 TO oDrives.count-1 STEP 2
		lcValue=ALLTRIM(UPPER(oDrives.Item[i+1]))
		IF	lcValue=pcValue
			lcRetVal=ADDBS(oDrives.Item[i])
			EXIT 
		ENDIF 
	ENDFOR 
	*
CASE pcAction = "M"   && Map a new drive letter
	*
	* pcValue should be "\\Server\volume" format
	* Find an unused Drive letter on Computer
	*
	DIMENSION laFields[1]
	LOCAL lnOnError,llError
	FOR i = 69 TO 90
		=ADIR(laFiles,CHR(i)+":" , "SV")
		IF EMPTY(laFiles[1])
			lcRetVal = CHR(i)+":"
			EXIT
		ENDIF
	ENDFOR
	IF !EMPTY(lcRetVal)
		lcOnError = ON("ERROR")
		ON ERROR llError=.t.
		WshNetWork.MapNetWorkDrive(lcRetVal , pcValue)
		ON ERROR &lcOnError		
	ENDIF
	*
	lcRetVal=IIF(llError,'',lcRetVal)
	RELEASE laFields,lcOnError,llError
	*
CASE pcAction = "R"   && Remove Drive letter Map
	*
	* pcValue should be "M:" format
	* Does the Drive Letter Map still exist
	*
	pcValue = LEFT(pcValue,2)
	LOCAL lcOnError,llError
	DIMENSION laFiles[1]
	*
	=ADIR(laFiles,pcValue , "SV")
	IF !EMPTY(laFiles[1])
		lcOnError = ON("ERROR")
		ON ERROR llError=.t.
		WshNetWork.RemoveNetWorkDrive(pcValue, .t., .t.)
		ON ERROR &lcOnError		
	ENDIF
	*
	lcRetVal=IIF(llError,pcValue,'')
	RELEASE laFiles,lcOnError,llError
	*
CASE pcAction = "S"   && Server Name for Drive Letter
	*
	* pcValue should be "M:" format
	* Check to see if UNC is in the array
	*
	FOR i=0 TO oDrives.count-1 STEP 2
		IF	ALLTRIM(UPPER(oDrives.Item[i])) = pcValue
			lcRetVal=ADDBS(oDrives.Item[i+1])
			EXIT 
		ENDIF 
	ENDFOR 
	*
CASE pcAction = "C"  && Computer Name
	lcRetVal=WshNetwork.ComputerName
	*
CASE pcAction = "D"   && Domain
	lcRetVal=WshNetwork.UserDomain
	*
CASE pcAction = "U"   && User NAme
	lcRetVal=WshNetwork.UserName
	*
ENDCASE 
*
RELEASE pcAction,pcValue
RELEASE WshNetwork,oDrives
RELEASE i,lcValue
RETURN 	lcRetVal


David W. Grewe Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top