nhoj
asked on
Network address instead of drive letter.
Using Microsoft Word it is possible to open and manipulate files on a network server by putting the IP address in the path instead of the drive letter.
Example:
I have a UNIX server with the IP number 193.133.116.1
I can map a file system on this server to drive on my PC,
say /data on the server to drive Fl appear in the windows explorer as /data on '193.133.116.1' (F:).
Obviously this is using TCP/IP as the network protocol.
I can then access this drive through Word as either F: or without mapping the drive as \\193.133.116\/data.
How can I use the second method with my applications in Delphi 3 ?
John Morin
Example:
I have a UNIX server with the IP number 193.133.116.1
I can map a file system on this server to drive on my PC,
say /data on the server to drive Fl appear in the windows explorer as /data on '193.133.116.1' (F:).
Obviously this is using TCP/IP as the network protocol.
I can then access this drive through Word as either F: or without mapping the drive as \\193.133.116\/data.
How can I use the second method with my applications in Delphi 3 ?
John Morin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) ExpandUNCFileName also copies the filename (ExpandUNCFileName('f:\aut oexec.bat' ) = '\\mycomputer\share_c\auto exec.bat' if drive F is mapped to \\mycomputer\share_c
2) It is possible, to have then same share mappet two different ways, eg. F: as \\mycomputer\share_c and G: as \\ip-number\share_c
Then ExpandUNCFileName('f:\auto exec.bat') = '\\mycomputer\share_c\auto exec.bat'
and ExpandUNCFileName('g:\auto exec.bat') = '\\ip-number\share_c\autoe xec.bat'
2) It is possible, to have then same share mappet two different ways, eg. F: as \\mycomputer\share_c and G: as \\ip-number\share_c
Then ExpandUNCFileName('f:\auto
and ExpandUNCFileName('g:\auto
nhoj, just map letter read file and unmap letter:
var
nr:TNetResource;
procedure TForm1.Button1Click(Sender : TObject);
begin
nr.lpRemoteName:=stralloc( 255);
nr.lpLocalName:=stralloc(2 55);
nr.dwType:=RESOURCETYPE_AN Y;
StrPCopy(nr.lplocalName, 'f:'); // let say H:
StrPCopy(nr.lpremoteName, '\\195.18.32.62\jecksom\co re');
nr.lpProvider:=nil;
if no_error=
WNetAddConnection2(nr,'pas sword','lo gin',CONNE CT_RESERVE D) then
begin
memo1.lines.LoadFromFile(' f:\core');
if no_error<>WNetCancelConnec tion2('h:' ,0,false) then
showmessage('error unmapping');
end else showmessage('error mapping');
strdispose(nr.lpRemoteName );
strdispose(nr.lpLocalName) ;
end;
Jecksom
var
nr:TNetResource;
procedure TForm1.Button1Click(Sender
begin
nr.lpRemoteName:=stralloc(
nr.lpLocalName:=stralloc(2
nr.dwType:=RESOURCETYPE_AN
StrPCopy(nr.lplocalName, 'f:'); // let say H:
StrPCopy(nr.lpremoteName, '\\195.18.32.62\jecksom\co
nr.lpProvider:=nil;
if no_error=
WNetAddConnection2(nr,'pas
begin
memo1.lines.LoadFromFile('
if no_error<>WNetCancelConnec
showmessage('error unmapping');
end else showmessage('error mapping');
strdispose(nr.lpRemoteName
strdispose(nr.lpLocalName)
end;
Jecksom
in my example must be :
WNetCancelConnection2('f:' ,0,false) // not h:
and
you have to change <IP> and <login> <password>.
WNetCancelConnection2('f:'
and
you have to change <IP> and <login> <password>.
Oh , line
memo1.Lines.LoadFromFile(' \\193.133. 116.1\reso urce\file' ); , working too.
memo1.Lines.LoadFromFile('
You don't have to map the share to read the file, you can just open the file as '\\server\share\filename'.
hustch: yes.
That's what I say.
A.
A.
333: yep, your first comment was answer on question , sorry , will wait when nhoj awake.
ASKER
nhoj is awake!
I need some time to try these things.
I need some time to try these things.
ASKER
\\server_name\directory_na me\file OR
\\IP_address\directory_nam e\file
work equally well.
When connecting to UNIX servers the slashes in the path must all be \ as in Windows and NOT / as is normal in UNIX. This is where I went wrong before.
Thanks
\\IP_address\directory_nam
work equally well.
When connecting to UNIX servers the slashes in the path must all be \ as in Windows and NOT / as is normal in UNIX. This is where I went wrong before.
Thanks
I'm not sure if it works with IP address, but i tested it with computer network name.
If you want to open a file on the network:
RichEdit1.Lines.LoadFromFi
If you have mapped drive and you want to get full path then:
label1.caption:=ExpandUNCF
If drive F is mapped to \\mycomputer\share_c then label1.caption will be
''\\mycomputer\share_c'
A.