<% // Adds a report to a folder. %>
<!-- #include file=RetrieveIStore.csp -->
<!-- #include file=helper_js.csp -->
function AddReport(FolderID, ReportName, InfoStore)
// Adds a report to a particular folder.
// The ID of the folder which will contain the report.
// The full path and file name of the report.
// The InfoStore used to communicate with the server.
// Returns the ID of the newly added report.
// If the function fails, it returns zero.
// Since reports are implemented using a plugin
// you will need the PluginManager to retrieve the Report plugin.
pmgr = InfoStore.PluginManager;
// Retrieve the Report plugin by passing the plugin's ProgID
// to the PluginInfo property of the PluginManager.
ReportPlugin = pmgr.PluginInfo("CrystalEnterprise.Report");
// Create a new, empty InfoObject collection.
NewCollection = InfoStore.NewInfoObjectCollection();
// Give the Report plugin object to the Add method. This
// creates a new InfoObject based on the plugin type.
// In this case, since the plugin is the Report plugin,
// the object created is a report object. The new report object
// is added to the empty collection.
NewReport = NewCollection.Add(ReportPlugin);
// Add the report data to the Files Collection. Do this using
// the collection's Add method. The report data may be specified
// in the form of a path and file name, or in a binary stream format
// that contains the report data. If a path is specified, it must be
NewReport.Files.Add (ReportName);
// The next line indicates where in the folder tree the
// report is to be added. It does this by setting the
// parent ID property or, in other words, by telling the report
// which folder it is to be placed in. If the parent ID property is
// zero, the report will not be committed properly. If the parent ID
// is not a folder, the report will not be committed properly.
NewReport.Properties.Add ("SI_PARENTID",FolderID);
// Retrieve the report's interface and try to enable
ireport = NewReport.PluginInterface;
ireport.EnableThumbnail = true;
// Use the InfoStore to commit the new collection with the new report
InfoStore.Commit (NewCollection);
// There was an error so return 0.
function GetFolderID(FolderName, IStore)
// Returns the ID of a folder given the folder name.
// It will search for all folders with this name anywhere
// in the tree and return the first one it finds.
// The folder ID or 0 if the function failed.
Result = IStore.Query("SELECT SI_ID FROM CI_INFOOBJECTS WHERE SI_PROGID='CrystalEnterprise.Folder' And SI_NAME = '" + FolderName + "'");
// There is a folder with that name.
// There may be more than one, but for this example just take the first.
// The main subroutine in the file. It logs on to the APS, retrieves the
// path and filename of the report as well as the folder in which the report
// will be placed and then adds it.
// The InfoStore object used to query the APS.
// The name of the folder that will store the report.
// The path and file name of the report.
Response.Redirect("Start.csp");
FolderName = Request.Form.Item ("FolderName");
ReportName = Request.Form.Item ("ReportName");
Response.Write("Getting folder ID of folder " + FolderName + " and adding the report, " + ReportName);
FolderID = GetFolderID(FolderName, IStore);
NewReportID = AddReport(FolderID, ReportName, IStore);
Response.Write ("<BR>Report added. <BR>");
Response.Write ("<BR>Couldn't add report.");
} else Response.Write ("<BR>The folder to which the report was to be added cannot be found.");
Crystal Decisions, Inc. http://www.crystaldecisions.com Support services: http://support.crystaldecisions.com |