Open document on the network - Delphi

0

How do I open a document, word, or PDF in the Delphi of the network?

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

I use the following command:

OpenDialog1.FileName := '\Servidor\c\sistema\documento.doc';
    
asked by anonymous 30.05.2016 / 15:23

1 answer

0

I believe that as the file is on another computer it looks 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;

Retired from here

    
30.05.2016 / 15:28