Folders.csp

To download the CSP files from this tutorial, click TutorialSamples.zip. For more information, see Code examples.

<HTML>

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

<BODY>

<%@ Language=JavaScript %>

<link REL=STYLESHEET TYPE='text/css' HREF='tut.css'>


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

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

<%


function PrintChildFolders(IStore, ParentID)

{

// This function prints 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.


//Notes:

//If an error occured the function returns false, otherwise it returns true.


    //The query that will select all the child folders.

    var Query;

    //The result of the query.

    var 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_PARENTID=" + ParentID;

            

        

    //Query the server.

    try {

        Result = IStore.Query(Query);

    }

    catch(e) {

        //There was an error querying the server.

        return(false);

    }


    var k;

    //Check that there are folders to view.

    if (Result.Count > 0) {

        //Retrieve the folder IDs from the query result.

        Response.Write ("<UL>")

        for(k=1;k<=Result.Count;k++)

        {

            Response.Write ("<LI>" + "<A HRef='Home.csp?FolderID="+Result.Item(k).ID + "' target='_top' >"+

            Server.HTMLEncode(Result.Item(k).Title) + "</A><BR>");

        }

        Response.Write ("</UL>")

    } else Response.Write ("No Sub-Folders");    


    return(true);

}


function RetrieveParentID(IStore, ChildID)

{


//This function retrieves the ID number of a particular folder's

//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:

//Returns the ID of the parent.


//Notes:

//If an error occured the function returns null.


    //The query that will select all the child folders.

    var Query;            


    //The result of the query.

    var 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'";

          

     //Query the server.

    try {

        Result = IStore.Query(Query);

    }

    catch(e) {

        //There was an error querying the server.

       return (null);

    }

      

    if (Result.Count > 0) {

        //Retrieve the ID from the query result.

        return( Result.Item(1).ParentID);

    } else

    return ("");

}


function RedirectWithFrames(URL)

{

    Response.Write ("<script language=javascript>open (\""+URL+"\",\"_top\");</script>");

}


var Result;

var FolderNames;

var FolderIDs;

var IStore;

var CurrentFolderID;


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

CurrentFolderID = Request.QueryString.Item("FolderID");

IStore=RetrieveIStore();


//Try to retrieve the InfoStore object.

if (IStore==null)

    //If it failed redirect the user to the logon page.

    

    RedirectWithFrames("LogonForm.csp");


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

else {


  Response.Write ("<B>Folders</B><BR><BR>");


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

    ParentID = RetrieveParentID(IStore,CurrentFolderID);

    //Check to see if the query was successful.

    if (ParentID != null) {


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

        if (CurrentFolderID != 0)

            Response.Write ("<A HRef='Home.csp?FolderID="+ParentID + "' Target='_top'>Up a Level</A><BR><BR>");

            

    }        

    else

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

  

  //Print the child folders.

  Result = PrintChildFolders(IStore,CurrentFolderID)

  if (!Result)

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

}

%>

</BODY>

</HTML>




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