EMC Developer Network

Get Folder Contents

February 2006

Software Environment

FeatureTested on
Operating SystemWindows 2000 Server SP4
LanguageC#
CompilerMicrosoft (R) Visual C# 2005 Compiler version 8.00.50727.42
RuntimeMicrosoft (R) Windows (R) 2005 Framework version 2.0.50727
DFC5.2.x,5.3, 5.3 SP1
DFC PIA5.3.0.53
Content Server5.3

Abstract

This snippet gets all the contents of a folder.

Snippet


using System;
using System.Collections.Generic;
using System.Text;
using Documentum.Interop.DFC;
using System.Runtime.InteropServices;

namespace CodeSnippets
{
    class GetFolderContents
    {

        public static void Main(String[] args)
        {
            GetFolderContents gfc = new GetFolderContents();            
            gfc.getFolderContents();
        }

        String username = "dmadmin";
        String password = "dmadmin";
        String repository = "devprog53sp1";
        string strFolderId = "0c017a1280000105";

        public void getFolderContents()
        {
            IDfId fldrId = null;
            IDfSession sess = null;
            IDfSessionManager sessMgr = null;
            IDfFolder fldr = null;
            IDfClientX clientX = null;
            IDfCollection coll = null;
            try{
                clientX = new DfClientXClass();
    
                fldrId = clientX.getId(strFolderId);

                sessMgr = CreateSessionManager();
                
                sess = sessMgr.getSession(repository);
                fldr = (IDfFolder)sess.getObject(fldrId);

                //this will get all sys objects and not just documents                                
                String attrList = "r_object_id,object_name";
                coll = fldr.getContents(attrList);
                while(coll.next())
                {
                    Console.WriteLine("ObjectId=" + coll.getString("r_object_id")+ ": ObjectName=" + coll.getString("object_name"));
                }
                Console.WriteLine("Finished");
                Console.ReadLine();
            }
            catch(COMException ex)
            {
                Console.WriteLine("Authentication Failed");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally{
                if(clientX != null) Marshal.ReleaseComObject(clientX);
                if (coll != null)
                {
                    try { coll.close(); }
                    catch (COMException cex2) { }
                    Marshal.ReleaseComObject(coll);
                }
                if(sess != null)
                {
                    sessMgr.release(sess);
                    Marshal.ReleaseComObject(sess);
                    Marshal.ReleaseComObject(sessMgr);
                }
                if(strFolderId != null) Marshal.ReleaseComObject(fldrId);
                if(fldr != null) Marshal.ReleaseComObject(fldr);
                
            }
        }



        private IDfSessionManager CreateSessionManager()
        {
            IDfClientX clientX = null;
            IDfClient localClient = null;
            IDfSessionManager sessMgr = null;
            IDfLoginInfo li = null;
            try
            {
                clientX = new DfClientXClass();

                li = clientX.getLoginInfo();
                li.setUser(username);
                li.setPassword(password);

                localClient = clientX.getLocalClient();
                sessMgr = localClient.newSessionManager();

                sessMgr.setIdentity(repository, li);                
            }
            catch (COMException ex)
            {
                Console.WriteLine("Authentication Failed");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);

            }
            finally
            {
                if (clientX != null) Marshal.ReleaseComObject(clientX);
                if (localClient != null) Marshal.ReleaseComObject(localClient);
                if (li != null) Marshal.ReleaseComObject(li);
            }
            return sessMgr;
        }
    }
}