Open network document - Delphi

Asked

Viewed 719 times

0

How do I open in Delphi a document, word or PDF, that is on the network?

Locally I can open, but when I use a network path (Ex.: \\Servidor\c\sistema\documento.doc) returns an error message that the file was not found.

I use the following command:

OpenDialog1.FileName := '\\Servidor\c\sistema\documento.doc';
  • Have you tried pasting this same path in Windows Explorer to make sure it is correct? A backslash is missing at the beginning of the path (before the server name, it uses two backslashes). Also check if there is even a share called "c" and if the intention was not to use the adminstrative share "c$".

1 answer

0


I believe that as the file is on another computer is something like this:

const
  RemoteName = '\\ntmemo01\C$';
  UserName = 'yourusername';
  Password = 'yourpassword';

function MapNetworkDrive: Boolean;
var
  NetRes: TNetResource;
  Res: DWord;
begin
  Result := True;
  FillChar(NetRes, SizeOf(TNetResource), 0);
  NetRes.dwType := RESOURCETYPE_DISK;
  NetRes.lpRemoteName := PChar(RemoteName);
  NetRes.lpLocalName := 'H:';   // Whatever drive letter you want
  Res := WNetAddConnection2(NetRes, PChar(Password), PChar(UserName), 0);
  Result := (Res = NO_ERROR);
end;

if not mapped

function UnMapNetworkDrive: Boolean;
var
  Res: DWord;
begin
  Res := WNetCancelConnection2(PChar('H:'), 0, True); // same drive letter as above
  Result := (Res + NO_ERROR);
end;

Withdrawn from here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.