Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

How to fetch an image document from FileNet for a known Document ID

5.00/5 (2 votes)
18 Dec 2011CPOL1 min read 50.6K  
How to fetch an image document from FileNet for a known Document ID

Prerequisite: FileNet IDM Desktop should be installed in the client machine. Add fnnfo.tbl as reference from "C:\Program Files\FileNet\idm\fnnfo.tbl".


Tips:



  1. The Document object's GetCachedFile function is the best function to use for this purpose. It returns the path to the document after it is retrieved to the local cache. Please refer to the IDM Desktop and Web Services Toolkit Help file for more details on its usage.
  2. Be aware that since the file resides in the local cache, you should copy it as soon as possible, because the Cache Manager may delete it to make room for other documents.
  3. Also make sure to copy the file - never move or delete, since this will probably cause an abort with the Cache Manager.
  4. You also need to know which product you are using and where it is running. If you are using IdmWs, the local cache is on the web server box. If using IdmDesktop, the local cache is on the client. This confuses many people.
  5. Lastly, a program like this can quickly overwhelm your system. Make sure your ephemeral ports are set to maximum. If you start experiencing errors after processing a large quantity of documents, this is usually an indicator that you have exhausted your system's resources. The only solution is to slow your code loop down.

Below is a simple application which takes the document ID from a textbox and saves the image retrieved from the FileNet Image server to c:\temp for that corrosponding document ID.


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace fileNet
{
    public partial class Form1 : Form
    {
        public static Object objMissing = System.Reflection.Missing.Value;
        public static IDMObjects.Neighborhood fnNebHood;
        public static IDMObjects.Library fnLibrary;

        public static IDMObjects.GenericObject fnGenericObj;
        public static IDMObjects.Document fnDoc;
        public static IDMObjects.idmObjectType fnObjectType;
        public static string fnCache ;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Boolean fnLogon;
            string fnUid = "your filenet userid";
            string fnPwd = "your filenet password";

            fnLibrary = new IDMObjects.Library();
            try
            {
                // Must logon to FileNet using IDMObjects.idmLibraryLogon.idmLogonOptNoUI
                // so that the logon is not cached.
                // If the logon is cached, then the FileNet cache is not cleared when logoff is executed
                if (!fnLibrary.GetState(IDMObjects.idmLibraryState.idmLibraryLoggedOn))
                    fnLogon = fnLibrary.Logon(fnUid, fnPwd, objMissing, 
                                IDMObjects.idmLibraryLogon.idmLogonOptNoUI);
                else
                    fnLogon = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "FileNet Login Error");
            }
            string docID = textBox1.Text;

            SaveDoc(docID);

            fnLibrary.Logoff();
        }

        public void SaveDoc(string argDocid)
        {

            fnObjectType = IDMObjects.idmObjectType.idmObjTypeDocument;

            try
            {
                fnGenericObj = fnLibrary.GetObject(fnObjectType, argDocid, 
                                         objMissing, objMissing, objMissing);
                fnDoc = (IDMObjects.Document)fnGenericObj;
                int pagec = fnDoc.PageCount;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            //' Write the file out to cache
            //' fileNm = the location of the file in cache
            //' To configure, the cache directory, use the IDM Configuration Tool
            //' Dim fileNm As String = fnDoc.GetCachedFile(0, "", 
            //'            idmGetCachedFileOptions.idmDocGetOriginalFileName)
            string fileNm = fnDoc.GetCachedFile(0, "",
                   IDMObjects.idmGetCachedFileOptions.idmDocGetOriginalFileName);
            string name = fnDoc.Name;
            fnDoc.Launch(IDMObjects.idmDocLaunchOption.idmDocLaunchIDMViewer);

            string onlyName = fnDoc.Name;
            string destFile = "C:\\Temp\\" + name + "_1.tif";

            File.Copy(fileNm, destFile,true);
            File.SetAttributes(destFile, FileAttributes.Normal);
        }
    }
}

If your document is a multiple page .tif image, then set the first argument of
GetCachedFile() to the page number which you want to fetch. Else you can loop that function for the pageCount to retrieve all the images.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)