{the following code constructs a relative URL pass the directory path of the file recieving the link and the path and filename of the file to be linked and the return value is a relative URL note that if you construct a URL from disk both URLs must be on the same drive (as though on the same server) if you connect to a file on another server you do not use relative URLs} unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl; type TForm1 = class(TForm) Button1: TButton; OpenDialog1: TOpenDialog; DirectoryListBox1: TDirectoryListBox; DriveComboBox1: TDriveComboBox; procedure Button1Click(Sender: TObject); function DoLink(RootsPath, PagesPath : string):string; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var s, t : string; begin s := DirectoryListBox1.Directory; {the path of the file accepting link} OpenDialog1.Execute; t := OpenDialog1.filename; {the path and filename of file to be linked} ShowMessage(s + chr(13) + t + chr(13) + DoLink(s, t)); end; function TForm1.DoLink(RootsPath, PagesPath : string):string; var i, j, k : integer; found : boolean; begin if pos(RootsPath, PagesPath) <> 0 then begin Result := copy(PagesPath, length(RootsPath) + 2, length(PagesPath) - Length(RootsPath) + 2); exit; end else begin i := 0; found := false; repeat repeat i := i + 1; until (RootsPath[i] = '\') or (i = length(PagesPath)) or (i = length(RootsPath)); if i >= length(PagesPath) then found := true else if copy(RootsPath, 1, i) <> copy(PagesPath, 1, i) then found := true; if not found then k := i; until found or (i = length(PagesPath)) or (i = length(RootsPath)); j := 1; If i <> length(RootsPath) then repeat i := i + 1; if (RootsPath[i] = '\') or (i = length(Rootspath)) then j := j + 1; until (i = length(RootsPath)); for i := 1 to j do Result := Result + '../'; Result := Result + copy(PagesPath, k + 1, length(PagesPath) - k + 1); for i := 1 to length(Result) do if Result[i] = '\' then Result[i] := '/'; end; end; end.