Folders.csp

To download the CSP files from this tutorial, click TutorialSamples_vb.zip. For more information about using the samples, see Code examples.


<HTML>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=charset=UTF-8">

<BODY>

<%@ Language=VBScript %>

<!-- #include file=RetrieveIStore.csp -->

<%



Function RetrieveChildFolders(IStore, ParentID , FolderNames, IDs)

'This function retrieves the names of child folders in a given folder.

'

'Precondition:

'IStore - The InfoStore object required to interface with server.

'ParentID - The ID of the parent folder containing the children to be retrieved.

'FolderNames - A variant to hold the folder names (This variable must be empty).

'IDs - A variant to the hold the folder IDs (This variable must be empty).

'

'Postcondition:

'FolderNames - An array containing the names of the child folders.

'IDs - An array containing the IDs of the child folders.

'

'Notes:

'The arrays are empty if there are no folders.  

'If an error occured the function returns FALSE, otherwise it returns TRUE.


    'The query that will select all the child folders.

    Dim Query  

    'The result of the query.

    Dim Result

        

    'Create a query that selects all the folders for a particular object.    

    'SI_PARENT_FOLDER is used to identify the parent folder.

    'SI_PROGID = 'CrystalEnterprise.Folder' specifies that we only want folders back.

    Query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where " & _

    "SI_PROGID = 'CrystalEnterprise.Folder' And SI_PARENT_FOLDER=" & CStr(ParentID)

        

On Error Resume Next

    'Query the server.

    Set Result = IStore.Query(Query)

    If Err.Number <> 0 Then

        'There was an error querying the server.

        RetrieveChildFolders=False

        Exit Function

    End If


    Dim k

    

    'Check that there are folders to view.

    If Result.Count > 0 Then

    'Reallocate the array to make room for the folder names.

    Redim FolderNames(Result.Count)

    Redim IDS(Result.Count)

    

        'Retrieve the folder IDs from the query result.

        k = 1

        Dim oFolder

        For each oFolder in Result

          FolderNames(k)=oFolder.Title

          Ids(k)=Result.Item(k).ID

          k = k+1

        Next


    End If


    'Indicate success.

    RetrieveChildFolders=True

End Function


Function RetrieveParentID(IStore, ChildID, ParentID)

'This function retrieves the ID number of a particular folders

'parent.

'

'Precondition:

'IStore - The InfoStore object required to interface with server.

'ChildID - The ID of the child whose parent ID is to be retrieved.

'

'Postcondition:

'ParentID - Stores the ID of the child's parent.

'

'Notes:

'ParentID will be empty if there is no parent.

'If an error occured the function returns FALSE, otherwise it returns TRUE.


    'The query that will select all the child folders.

    Dim Query            


    'The result of the query.

    Dim Result            

      

    'Create a query that selects the parent's ID for a folder.

    Query = "Select SI_PARENTID From CI_INFOOBJECTS Where SI_ID = " & _

    ChildID & " And SI_PROGID = 'CrystalEnterprise.Folder'"

          

On Error Resume Next

    'Query the server.

    Set Result = IStore.Query(Query)

    If Err.Number <> 0 Then

        'There was an error querying the server.

        RetrieveParentID=False

        Exit Function

    End If

      

    If Result.Count > 0 Then

        'Retrieve the ID from the query result.

        ParentID = Result.Item(1).ParentID

    End If

    RetrieveParentID=True

End Function


Dim Result

Dim FolderNames

Dim FolderIDs

Dim IStore

Dim CurrentFolderID


'Retrieve the CurrentFolderID from the file's parameter list.

CurrentFolderID = Request.QueryString("FolderID")



'Try to retrieve the InfoStore object.

If RetrieveIStore(IStore)=FALSE then

    'If it failed, redirect the user to the logon page.

    Response.Redirect "LogonForm.csp"


'Otherwise display the folders and the "Up a Level" link.

Else

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


  '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


End If


%>

</BODY>

</HTML>




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