public void deleteUserFromPermissions(string userSearchPath, CognosReportNetService crnService, string sPath)
        {
            //set searchPath of the required folder
            //searchPathMultipleObject spMulti = new searchPathMultipleObject();
            //spMulti.Value = sPath;
            report pFolder = (report)crnService.query(sPath, new propEnum[]{propEnum.searchPath,propEnum.policies},new sort[]{},new queryOptions())[0];

            //keep trak if the aecurity object was found in the permissions
            bool found = false;

            for (int i = 0; i < pFolder.policies.value.Length && !found; i ++)
            {
                policy policy = pFolder.policies.value[i];
                //If the security object already exists, update its permissions
                if(policy.securityObject.searchPath.value.Equals(userSearchPath))
                {
                    found = true;
                }
            }
            //if the security object exists, remove it from the array of permissions
            if (found)
            {
                policy[] newPolicies = new policy[pFolder.policies.value.Length-1];
                policyArrayProp pArray = new policyArrayProp();
                int newPolicyCount  = 0;
                for (int i = 0; i < pFolder.policies.value.Length ; i ++)
                {
                    policy policy = pFolder.policies.value[i];
                    if(!policy.securityObject.searchPath.value.Equals(userSearchPath))
                    {
                        newPolicies[newPolicyCount] = new policy ();
                        newPolicies[newPolicyCount].securityObject = pFolder.policies.value[i].securityObject;
                        newPolicies[newPolicyCount].permissions  = pFolder.policies.value[i].permissions;
                        newPolicyCount = newPolicyCount + 1;
                    }

                }
                //If the security object does not exist, nothing to delete
                pArray.value = newPolicies;
                pFolder.policies = pArray;
                crnService.update(new baseClass[]{pFolder},new updateOptions() );
            }
        }
        /// <summary>
        /// Application entry point.
        /// </summary>
        /// <param name="args">Standard command-line arguments.</param>
        public static void Main( string[] args )
        {
            // Attempt a simple CM query.

            string searchPath = "//report";
            string userName = "******";
            string userPassword = "******";
            string userNamespace = "namespaceID";

            char[] arg_separator = { '=' };
            foreach( string arg in args )
            {
                string[] command = arg.Split( arg_separator, 2 );

                switch( command[0] )
                {
                case "--search":
                    searchPath = command[1];
                    break;
                case "--uid":
                    userName = command[1];
                    break;
                case "--pwd":
                    userPassword = command[1];
                    break;
                case "--namespace":
                    userNamespace = command[1];
                    break;
                default:
                    throw new ApplicationException( "Unknown argument: " + arg );
                }
            }

            // Concatenate the read filter to the searchPath this way we
            // ask CM to only return the objects we have read acces on.
            searchPath = searchPath + "[permission('read')]";

            // Create the ReportNet connection object.
            Console.WriteLine( "Creating CognosReportNetService..." );
            CognosReportNetService crn = new CognosReportNetService();
            crn.Url = "http://localhost:8080/series8/cgi-bin/cognos.cgi";

            // Add the authentication information, if any.
            //
            // Another option would be to use the logon() methods...
            CAM cam = new CAM();
            cam.action = "logonAs";

            hdrSession header = new hdrSession();
            if( userName != null )
            {
                formFieldVar[] vars = new formFieldVar[3];

                vars[0] = new formFieldVar();
                vars[0].name = "CAMNamespace";
                vars[0].value = userNamespace;
                vars[0].format = formatEnum.not_encrypted;

                vars[1] = new formFieldVar();
                vars[1].name = "CAMUsername";
                vars[1].value = userName;
                vars[1].format = formatEnum.not_encrypted;

                vars[2] = new formFieldVar();
                vars[2].name = "CAMPassword";
                vars[2].value = userPassword;
                vars[2].format = formatEnum.not_encrypted;

                header.formFieldVars = vars;
            }
            else
            {
                cam.action = "logon";
            }

            biBusHeader bibus = new biBusHeader();
            bibus.CAM = cam;
            bibus.hdrSession = header;

            crn.biBusHeaderValue = bibus;

            try

            {

                propEnum[] props = new propEnum[] { propEnum.searchPath,
                                                      propEnum.defaultName, propEnum.policies,
                                                      propEnum.permissions, propEnum.members };

                sort[] s = new sort[]{ new sort() };

                s[0].order = orderEnum.ascending;

                s[0].propName = propEnum.defaultName;

                queryOptions qo = new queryOptions();
                // Look for all of the reports.

                Console.WriteLine( "\nReports:\n" );

                baseClass[] bc = crn.query( "/content//report", props, s, qo );

                if( bc.Length > 0 )
                {
                    foreach( baseClass report_item in bc )

                    {
                        Console.WriteLine( "  {0}", report_item.searchPath.value);
                        policy[] p = report_item.policies.value;
                        if (p.Length > 0)
                        {
                            foreach( policy pol in p )
                            {
                                Console.WriteLine( "  {0}", pol.securityObject.searchPath.value);
                                permission[] perm = pol.permissions;
                                foreach( permission prm in perm )
                                    Console.WriteLine( "  {0}   {1}",prm.name, prm.access.ToString());
                            }
                        }
                    }
                }
            }

            catch( System.Web.Services.Protocols.SoapHeaderException ex )
            {
                Console.WriteLine( "SOAP Header Exception:" );
                Console.WriteLine( "Actor  : " + ex.Actor );
                Console.WriteLine( "Code   : " + ex.Code );
                Console.WriteLine( "Detail : " + ex.Detail );
                Console.WriteLine( "Message: " + ex.Message );

                // We can access the SOAP fault information through
                // the ex.Detail property.
                System.Xml.XmlNode node = ex.Detail;
                Console.WriteLine( node.OuterXml );
            }
            catch( System.Web.Services.Protocols.SoapException ex )
            {
                Console.WriteLine( "SOAP Exception:" );
                Console.WriteLine( "Actor  : " + ex.Actor );
                Console.WriteLine( "Code   : " + ex.Code );
                Console.WriteLine( "Detail : " + ex.Detail );
                Console.WriteLine( "Message: " + ex.Message );

                // We can access the SOAP fault information through
                // the ex.Detail property.
                System.Xml.XmlNode node = ex.Detail;
                Console.WriteLine( node.OuterXml );
            }
        }
        public string doQuery(CognosReportNetService reportNet, 
			string searchPath, 
			string userName, 
			string userPassword, 
			string userNamespace,
			bool isGUImode)
        {
            string output = "";
            try
            {
                // Search properties: we need the defaultName and the searchPath.
                propEnum[] properties =
                { propEnum.defaultName, propEnum.searchPath };

                // Sort options: ascending sort on the defaultName property.
                sort[] sortBy = { new sort()};
                sortBy[0].order = orderEnum.ascending;
                sortBy[0].propName = propEnum.defaultName;

                // Query options; use the defaults.
                queryOptions options = new queryOptions();

                // Add the authentication information, if any.
                //
                // Another option would be to use the logon() and logonAs() methods...
                CAM cam = new CAM();
                cam.action = "logonAs";

                hdrSession header = new hdrSession();
                if ((userName != null) && (0 != userName.CompareTo("")) )
                {
                    formFieldVar[] vars = new formFieldVar[3];

                    vars[0] = new formFieldVar();
                    vars[0].name = "CAMNamespace";
                    vars[0].value = userNamespace;
                    vars[0].format = formatEnum.not_encrypted;

                    vars[1] = new formFieldVar();
                    vars[1].name = "CAMUsername";
                    vars[1].value = userName;
                    vars[1].format = formatEnum.not_encrypted;

                    vars[2] = new formFieldVar();
                    vars[2].name = "CAMPassword";
                    vars[2].value = userPassword;
                    vars[2].format = formatEnum.not_encrypted;

                    header.formFieldVars = vars;
                }
                else
                {
                    cam.action = "logon";
                }

                biBusHeader bibus = new biBusHeader();
                bibus.CAM = cam;
                bibus.hdrSession = header;

                reportNet.biBusHeaderValue = bibus;

                // Make the query.
                baseClass[] results =
                    reportNet.query(searchPath, properties, sortBy, options);

                // Display the results.
                output += "Results:\n\n";
                for (int i = 0; i < results.GetLength(0); i++)
                {
                    tokenProp theDefaultName = results[i].defaultName;
                    stringProp theSearchPath = results[i].searchPath;

                    output += "\t" + theDefaultName.value + "\t\t" + theSearchPath.value + "\n";
                }
            }
            catch(SoapException ex)
            {
                SamplesException.ShowExceptionMessage("\n" + ex, isGUImode, "Content Manager Query Sample - doQuery()" );
                return "The error occurred in doQuery()";
            }
            catch(System.Exception ex)
            {
                if (0 != ex.Message.CompareTo("INPUT_CANCELLED_BY_USER"))
                {
                    SamplesException.ShowExceptionMessage("\n" + ex.Message, isGUImode, "Content Manager Query Sample - doQuery()" );
                }
                return "The error occurred in doQuery()";
            }
            return output;
        }
        public void setPermissionsOnFolders(string userSearchPath, CognosReportNetService crnService, string sPath)
        {
            report pFolder = (report)crnService.query(sPath, new propEnum[]{propEnum.searchPath,propEnum.policies},new sort[]{},new queryOptions())[0];

            bool found = false;
            permission newPermission = new permission();
            newPermission.name ="execute";
            newPermission.access = accessEnum.deny;

            for (int i = 0; i < pFolder.policies.value.Length && !found; i ++)
            {
                policy policy = pFolder.policies.value[i];
                //If the security object already exists, update its permissions
                if(policy.securityObject.searchPath.value.Equals(userSearchPath))
                {
                    found = true;
                    permission[] newPerms = new permission[policy.permissions.Length + 1];
                    for(int j = 0; j < policy.permissions.Length; j ++)
                    {
                        newPerms[j] = policy.permissions[j];
                    }
                    newPerms[newPerms.Length - 1] = newPermission;
                    policy.permissions = newPerms;
                }
            }
            //If the security object does not exist, create a new one
            if(!found)
            {
                baseClass entry = null;
                //spMulti.Value = userSearchPath;
                entry = crnService.query(userSearchPath, new propEnum[]{},new sort[]{},new queryOptions())[0];

                policy newPolicy = new policy();
                newPolicy.securityObject = entry;
                permission[] permissions = new permission[1];
                permissions[0] = newPermission;
                newPolicy.permissions = permissions;

                policyArrayProp existingPols = pFolder.policies ;
                policy[] newPols = new policy[existingPols.value.Length + 1];
                for(int j = 0; j < existingPols.value.Length; j ++)
                {
                    newPols[j] = existingPols.value[j];
                }
                newPols[newPols.Length - 1] = newPolicy;
                existingPols.value = newPols;
            }

            crnService.update(new baseClass[]{pFolder},new updateOptions() );
        }