The GetFolders method returns a collection of folders, either at the top level or under the specified folder ID. This collection contains objects with the following properties:

NameDescription
ID The folder ID.
FolderName The folder name.
DisplayName The folder name as displayed to the user.
HasChildren True if there are report or folders containing reports within this folder, or False if not.
Reports The number of reports in this folder and its subfolders.
Folders The number of folders in this folder and its subfolders.
HasFolders True if there are folders within this folder, or False if not.
Directory The full path to the physical folder on disk.
Path The path to the folder.
ParentID The ID of this folder's parent folder; 0 if this parent is a top-level folder.
CreatedBy The name of the user who created this folder.
CreatedAt The date and time the folder was created.

This method is useful if you want to display a list of folders and the reports in those folders from an application using the SQProxy object.

Syntax

GetFolders([FolderID as Integer [, UserName as String]])
    as Collection

Parameters
FolderID
The ID of the folder to get the folders from. Omit this parameter or pass 0 to retrieve top-level folders.

UserName
If this is specified, the returned collection contains only those folders the specified user has access to.

Return Value
A collection of folder objects.

Example

Visual FoxPro
This code fills a TreeView control named oTreeView with all of the folders and reports a user has access to.

local loQuery, loFolders, loFolder
loQuery = createobject('SQProxy.SQProxy')
loQuery.LoadProject('\development\sqdemo\nwind', 'admin', 'admin')
if loQuery.ProjectLoaded
  loFolders = loQuery.SQApplication.ReportEngine.GetFolders()
  for each loFolder in loFolders
    ProcessFolder(loQuery.SQApplication.ReportEngine, loFolder)
  next
endif
return

function ProcessFolder(toReportEngine, toFolder)
local loFolders, loFolder, loReports, loReport
AddFolderToTree(toFolder)
if toFolder.HasChildren
  loFolders = toReportEngine.GetFolders(toFolder.ID)
  for each loFolder in loFolders
    ProcessFolder(toReportEngine, loFolder)
  next
endif toFolder.HasChildren
loReports = toReportEngine.GetReports(toFolder.ID)
for each loReport in loReports
  AddReportToTree(loReport, toFolder)
next
return

function AddFolderToTree(toFolder)
local lcKey, lcParentKey
lcKey = 'F' + toFolder.ID
if toFolder.ParentID = 0
  oTreeView.Nodes.Add(, 1, lcKey, toFolder.FolderName)
else
  lcParentKey = 'F' + toFolder.ParentID
  oTreeView.Nodes.Add(lcParentKey, 4, lcKey, toFolder.FolderName)
endif
return

function AddReportToTree(toReport, toFolder)
local lcFolderKey, lcKey
lcFolderKey = 'F' + toFolder.ID
lcKey = 'R' + toReport.ID
oTreeView.Nodes.Add(lcFolderKey, 4, lcKey, toReport.ReportName)
return

C#

The .NET ReportEngine class already contains a method (FillTreeView) that fills a TreeView object with Stonefield Query folders and reports for you automatically. Below is the code that it uses internally which demonstrates the use of ReportEngine.GetFolders.

public void FillTreeView(TreeView treeView)
{
  treeView.BeginUpdate();

  treeView.Nodes.Clear();

  // For each top-level folder
  foreach (Folder folder in this.GetFolders())
  {
    ProcessFolder(treeView.Nodes, folder);   
  }

  treeView.EndUpdate();
}

private void ProcessFolder(TreeNodeCollection nodes, Folder folder)
{
  string folderKey = 'F' + folder.ID.ToString();

  TreeNode newNode = nodes.Add(folderKey, folder.FolderName);

  // Add any child folders recursively
  if(folder.HasFolders)
  {
    foreach (Folder childFolder in this.GetFolders(folder.ID))
    {
      ProcessFolder(newNode.Nodes, childFolder);
    }
  }

  // Now add any reports for this folder
  Reports reports = this.GetReports(folder.ID);

  foreach (Report report in reports)
  {
    string reportKey = 'R' + report.ID.ToString();

    newNode.Nodes.Add(reportKey, report.ReportName);
  }
}

In C# You can use this function with code like:

SQProxy sqProxy = new SQProxy();

sqProxy.LoadProject(@"C:\Program Files\Stonefield Query SDK\Sample Project");

while (!sqProxy.ProjectLoaded)
{
}
            
System.Windows.Forms.TreeView treeView = new System.Windows.Forms.TreeView();
sqProxy.SQApplication.ReportEngine.FillTreeView(treeView);

VB.NET

In VB.NET you can use this function with code like:

Dim sqProxy as SQProxy = new SQProxy()

sqProxy.LoadProject("C:\Program Files\Stonefield Query SDK\Sample Project")

while Not sqProxy.ProjectLoaded
End While

Dim treeView as System.Windows.Forms.TreeView = new System.Windows.Forms.TreeView()
sqProxy.SQApplication.ReportEngine.FillTreeView(treeView)

See also

GetReports | ReportEngine Object | SQProxy Object

© Stonefield Software Inc., 2023 • Updated: 12/21/18
Comment or report problem with topic