Jump to content

Show content of FilesFolderURL in a TUniURLFrame


Jean-Marc Kiener

Recommended Posts

My app runs as exe or service.

 

I try to show all the content of UniServerModule.FilesFolderURL in a TUniURLFrame:

myURLFrame.URL :=  ExcludeTrailingPathDelimiter( UniSession.URL ) +  UniServerModule.FilesFolderURL ;

In other words, i try to show http://localhost:8077/files/in the browser. I always get a "Invalid Session or Session timeout".

It is possible to set "Directory listing" on for this directory.

 

In general, how to set a directory for simple directory listing in UniServer?

example: http://localhost:8077/myOwnDirectory/

 

 

 

Link to comment
Share on other sites

Found this in \FMSoft\Framework\uniGUI\Demos\Touch\PDFView:
 

var
  FFolder : string;
  Sr : TSearchRec;
begin
  UnimList1.Items.Clear;
  FFolder := UniServerModule.FilesFolderPath+'PDFs\';
  if SysUtils.FindFirst(FFolder+'*.pdf', faAnyFile, Sr) = 0 then
  begin
    repeat
      if Sr.Attr and faDirectory = 0 then
        UnimList1.Items.Add(Sr.Name);
    until SysUtils.FindNext(sr) <> 0;
    SysUtils.FindClose(sr);
  end;
  if UnimList1.Items.Count > 0 then
    UnimList1.ItemIndex := 0;
end;

HTH.

  • Upvote 1
Link to comment
Share on other sites

Thanks NEO4A.

Yes, i came to an similar approach. Do it the UniGui Way ;-).

The build-in-HTTPServer seems not to be able to configure a directory for delivering and Browsing.

 

So i did the following ( based on http://www.swissdelphicenter.ch/en/showcode.php?id=400 )

procedure TfrmMain.CreateDocumentTree;

  procedure GetDirectories(Tree: TUniTreeView; Directory: string; Item: TUniTreeNode; IncludeFiles: Boolean);
  var
    SearchRec: TSearchRec;
    ItemTemp: TUniTreeNode;
  begin
    Tree.Items.BeginUpdate;
    if Directory[Length(Directory)] <> '\' then Directory := Directory + '\';
    if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then
    begin
      repeat
        if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] <> '.') then
        begin
          if (SearchRec.Attr and faDirectory > 0) then
            Item := Tree.Items.AddChild(Item, SearchRec.Name);
          ItemTemp := Item.Parent;
          GetDirectories(Tree, Directory + SearchRec.Name, Item, IncludeFiles);
          Item := ItemTemp;
        end
        else if IncludeFiles then
          if SearchRec.Name[1] <> '.' then
            Tree.Items.AddChild(Item, SearchRec.Name);
      until FindNext(SearchRec) <> 0;
      FindClose(SearchRec);
    end;
    Tree.Items.EndUpdate;
  end;

begin
  treeDocuments.BeginUpdate;
  treeDocuments.Items.Clear;
  try
    GetDirectories(treeDocuments, FDocumentsPath, nil, True);
  finally
    treeDocuments.EndUpdate;
  end;
end;
procedure TfrmMain.treeDocumentsDblClick(Sender: TObject);
var
  FilePath: string;
  n: TUniTreeNode;
begin
  n := treeDocuments.Selected;
  FilePath := n.Text;
  while n.Parent <> nil do begin
    n := n.Parent;
    Filepath := n.Text + '\' + Filepath;
  end;
  FilePath := FDocumentsPath + FilePath;
  if TFile.Exists( FilePath ) then
    UniSession.SendFile( FilePath );
end;
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...