on 07-07-2009 8:34 PM
Hello everyone,
I'm having a difficulty with countin files in a Regular folder and subfolders of the folder. I've tried to use SI_ANCESTOR in a query; however, it gives me innacurate results.
I used this hierarchy to create the code below, and it works to count all the files:
Folder A ---> Folder B( subFolder of A) -
> Folder C(subFolder of B)
//get folder A
IInfoObjects regFolders = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_KIND='Folder' AND SI_PARENTID=0 AND SI_NAME!='User Folders' Order by SI_NAME");
IFolder regFolder = (IFolder) regFolders.get(0);
//get files from Folder A
IInfoObjects rFiles = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID ! = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + regFolder.getID() );
ilesCount += rFiles.size();
int subCntr=0;
nt subCntr2=0;
//get folder B
IInfoObjects rSubFolders = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + regFolder.getID() );
//get files from subFolders of Folder A
while (subCntr < rSubFolders.size())
{
IInfoObject subFolder=(IInfoObject)rSubFolders.get(subCntr);
IInfoObjects subFiles = infoStore.query ("SELECT * FROM CI_INFOOBJECTS "
+ " WHERE SI_PROGID != 'CrystalEnterprise.Folder'" AND SI_PARENTID=" + subFolder.getID() );
filesCount += subFiles.size();
//get subFolders of Folder B
IInfoObjects rSubFolders2 = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + subFolder.getID() );
//get files from subFolders of Folder B
while (subCntr2 < rSubFolders2.size())
{
IInfoObject subFolder2=(IInfoObject)rSubFolders2.get(subCntr2);
IInfoObjects subFiles2 = infoStore.query ("SELECT * FROM CI_INFOOBJECTS "
+ " WHERE SI_PROGID != 'CrystalEnterprise.Folder' AND SI_PARENTID=" + subFolder2.getID() );
filesCount += subFiles2.size();
subCntr2++;
}
subCntr++;
}
As you can see, the code is too complicated, and what if folder C has subFolder?
I'm guessin maybe recursion would be one way to got, but I'm not really good with it, so I was wondering if anyone has any idea on how to go about doing it.
Thank you,
Hi,
I am not sure if you need such a complicated code. You need to use recursion as shown in code sample below. It begins at top level folders just like in yoru code and then digs in through each of the subfolders in top folders using recursion.
<%@ page import="com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.plugin.desktop.report.*,
com.crystaldecisions.sdk.plugin.desktop.common.*,
com.crystaldecisions.sdk.exception.SDKException"%>
<%
String username = "administrator";
String password = "password";
String cmsname = "cms name";
String authtype = "secEnterprise";
IEnterpriseSession oEnterpriseSession = null;
try
{
oEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authtype);
IInfoStore oInfoStore = (IInfoStore)oEnterpriseSession.getService("","InfoStore");
String query = "select * from ci_infoobjects where si_kind='folder' and si_parentid=0 and si_name != 'User Folders'";
IInfoObjects topFolders = oInfoStore.query(query);
if(topFolders.size() < 1)
out.println("no top level folders");
else
{
for(int i=0; i<topFolders.size(); i++)
{
IInfoObject topFolder = (IInfoObject) topFolders.get(i);
int num = GetSubFolders(oInfoStore, topFolder.getID());
}
}
}
catch(SDKException e)
{
out.println(e.toString());
}
finally
{
if ( oEnterpriseSession != null)
oEnterpriseSession.logoff();
}
%>
<%! int GetSubFolders(IInfoStore oInfoStore, int folderID) throws SDKException
{
String query = "select * from ci_infoobjects where si_kind='folder' and si_parentid=" + folderID;
IInfoObjects folders = oInfoStore.query(query);
if(folders.size() < 1)
return 0;
else
{
for(int i=0; i<folders.size(); i++)
{
int numOfSF = GetSubFolders(oInfoStore, ((IInfoObject)folders.get(i)).getID());
}
return folders.size();
}
}
%>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
For detailed information, please refer to the BI 4.0 developers guide here.
You can find the section "Setting up the development environment" in developers guide that have every single instruction to execute a java code specific to BI 4.0 environment.
Also, here are the instructions for BO 3.1 environment:
To configure a WAR file for a J2EE application that uses the BusinessObjects Enterprise XI 3.0 and 3.1 Java SDK, complete these steps:
You are now able to run an application using the BusinessObjects Enterprise XI 3.0 and 3.1 Java SDK on a J2EE web application server.
Hope it helps.
Regards,
Anchal
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.