Retrieving the child folders for the current folder

In the next part of the code, the InfoStore object is retrieved using the RetrieveIstore function.

If RetrieveIStore(IStore)=FALSE then

    Response.Redirect "LogonForm.htm"

Else

    Response.Write "<B>Folders</B><BR><BR>"

If the RetrieveIStore function fails, then there is a rather large problem: there is no way to authenticate the current user. Thus, the only option available is to redirect the user back to the logon page. If the RetrieveIstore function succeeds, then the folders are displayed for the authenticated user.

Example


'Retrieve the child folders for the current folder.

Result = RetrieveChildFolders(IStore,CurrentFolderID,FolderNames,FolderIDs)


'Check to see if the function was successful.

If result=True then

    Dim ParentID


    'Retrieve the parent's ID for the current folder.

    Result = RetrieveParentID(IStore,CurrentFolderID,ParentID)

    

    'Check to see if the query was successful.

    If Result = TRUE Then


        'If this is not the top level of folders display the "Up a Level" link.

        If Not IsEmpty(ParentID) And (CurrentFolderID<>0) Then

            Response.Write "<A HRef='home.csp?FolderID="&ParentID & "' Target='_top'>Up a Level</A><BR><BR>"

        End If


        'If there are sub-folders display a link to them.

        If Not isEmpty(FolderNames) Then

            Dim k

            For k = 1 to UBound(FolderNames)

                Response.Write "&#149&nbsp;" & "<A HRef='home.csp?FolderID="&FolderIDs(k) & "' target='_top' > "& _

                Server.HTMLEncode(FolderNames(k)) & "</A><BR>"

            Next

        Else

            Response.Write "No Sub-Folders."

        End If

    Else

        Response.Write "There was an error trying to retrieve the parent folder."

    End If

Else

    Response.Write "There was an error trying to retrieve the sub-folders."

End If

Remarks

The most interesting lines in this slice of code are the two responses:

Response.Write "<A HRef='home.csp?FolderID="&ParentID & "' Target='_top'>Up a Level</A><BR><BR>"

and

Response.Write "<A HRef='home.csp?FolderID="&FolderIDs(k) & "' target='_top' > "& _

Server.HTMLEncode(FolderNames(k)) & "</A><BR>"

The first displays a link that returns the user to a folder one level up in the folder tree, and the second displays a link to one of the sub-folders in the current directory. The links themselves take on the form

<a href='Home.csp?FolderID=AFolderID'>Folder Name</a>

The link instructs the page Home.csp to be loaded. This page hasn't been discussed yet, but it is important in that it provides the frames definition for a home page. It divides the browser window into three separate frames and loads the Folders pages into the left most frame. See Home Page.

The CurrentFolderID is given to the frames page so that it can pass it on to both the Folders.csp page and the Reports.csp page, which you will examine shortly. Consequently, both the Folders page and the Reports page are loaded with a new folder ID and display both the sub-folders and the reports for that page.

To give you a better idea of how the folders page works, here is the HTML code that was produced by the Folders page at the top level of the myAPS folder tree.

<a href='home.csp?FolderID=885'>-Tutorial Folder 1</a><BR>

<a href='home.csp?FolderID=886'>-Tutorial Folder 2</a><BR>

There are two top-level folders in this example. Each of them has a corresponding ID number. Assume that you click the link to Tutorial Folder 1 . When this happens, its ID number (885) is be sent to the frames page, which will re-load the folders page and hand it the new ID. The folders page will then display all the sub-folders for Tutorial Folder 1.

End of lesson

You now have a working copy of Folders.csp. To see a full version of the CSP page that you've created, see Folders.csp

Go to next lesson:

Lesson 2b: Listing the reports in a folder



Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com