AddFolder.csp

<%@ Language=JavaScript %>

<% // Adds a folder given a parent ID. If the parent ID is 0, the folder

// is added to the top level. %>

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


<HTML>

<HEAD>

</HEAD>

<BODY>

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

<%

function AddFolder(ParentFolderID, FolderName, FolderDescription, InfoStore)

{

// Creates a new folder.

//

// PARAMETERS

//

// ParentFolderID [IN]

//     The ID of the folder's parent folder.

// FolderName [IN]

//     The new folder's name.

// FolderDescription [IN]

//     A description of the folder.

// InfoStore

//     The InfoStore used to communicate with the server.


// RETURNS

// Returns the ID of the newly created folder

// If the function fails, it returns zero.


    // The plugin manager.

    var pmgr;


    // The Folder plugin.    

    var FolderPlugin;


    // Step 1

    // Since folders are implemented using a plugin

    // you will need the PluginManager to retrieve the folder plugin.

     pmgr = InfoStore.PluginManager;


    // Step 2

    // Retrieve the Report plugin by passing the plugin's ProgID

    // to the PluginInfo property of the PluginManager.

     FolderPlugin = pmgr.PluginInfo("CrystalEnterprise.Folder");


    var NewCollection;

    var NewFolder;


    // Step 3

    // Create a new, empty InfoObject collection.    

     NewCollection = InfoStore.NewInfoObjectCollection();


    // Step 4

    // Give the Folder plugin object to the Add method.  This

    // creates a new InfoObject based on the plugin type.

    // In this case, since the plugin is the folder plugin,

    // the object created is a folder object.

     NewFolder = NewCollection.Add(FolderPlugin);


    // Step 5

    // Specify the folder's details.

    NewFolder.Title = FolderName;

    NewFolder.Description = FolderDescription;

    // The next line indicates where in the folder tree the

    // folder is to be created.  It does this by setting the

    // parent ID property or, in other words, by telling the folder

    // which folder is its parent. If the parent ID property is

    // zero, then the folder has no parent and is thus a top

    // level folder.

    NewFolder.Properties.Add ("SI_PARENTID",ParentFolderID);

    //NewFolder.ParentID = ParentFolderID



    // Step 6    

    // Use the InfoStore to commit the new collection with the new folder

    // to the APS database.

    try {

        InfoStore.Commit (NewCollection);

    }

    catch(e) {

        // If the function failed return zero.

        return 0;

    }

    // Return the new folder's ID.  The ID is assigned by the APS

    // once the folder has been created.

        return (NewFolder.Id);

}


function Main()

{

// The main subroutine in the file.  It logs on to the APS, retrieves the

// folder description, folder name and adds the folder.  It then adds a folder

// beneath the folder that was just added.

// On Error Resume Next

    // The InfoStore object used to query the APS.

    var IStore;

    // The name of the folder to be added.

    var FolderName;

    // A description of the folder.

    var FolderDescription;

        

    // Logon and retrieve InfoStore.

    IStore = RetrieveIStore();

    if (IStore==null)

        Response.Redirect ("Start.csp");

    else

    {

        FolderName = Request.Form.Item ("FolderName")

        FolderDescription = Request.Form.Item ("FolderDescription")

        var NewFolderID;

        // Add the top-level folder.

        NewFolderID = AddFolder( 0, FolderName, FolderDescription, IStore);

        if (NewFolderID != 0)  {

            Response.Write ("Top-level folder added. <BR>");

            // Add the subfolder.

            if (AddFolder(NewFolderID,"Subfolder of " + FolderName, "",IStore) != 0 ) {

                Response.Write ("Subfolder added.");

            } else {

            Response.Write ("Subfolder not added");

            }

        } else {

            Response.Write ("Folder not added");

        }

    }

}


Main(); // Start the script

%>

</BODY>

</HTML>





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