Thursday, March 12, 2009

Documentum and C# .Net

This is a code sample of C# and Documentum.

Things to remember:
  1. You need DFC with the Primary Interoperability Assembly. Since the introduction of DFS, the latest DFC that supports this is 5.3
  2. DFC and Java must be installed on your dev machine.
  3. I used the free Visual Studio C# 2008 Express from Microsoft to test this

string DOCBASE = "gel";
string DOCBASE_USER = "dmadmin";
string DOCBASE_PWD = "dmadmin";
string DOCBASE_FOLDER = "/BDO Ocav";
DFCLib.DfClientX clientX = new DFCLib.DfClientX();
DFCLib.IDfClient client;
DFCLib.IDfSession session;

//this is how you connect to the repository

private void OpenDctm()
{

client = clientX.getLocalClient();
DFCLib.IDfLoginInfo loginInfo = clientX.getLoginInfo();
loginInfo.setDomain("");
loginInfo.setUser(DOCBASE_USER);
loginInfo.setPassword(DOCBASE_PWD);
session = client.getSharedSession(DOCBASE, loginInfo, "MyKey");
}

//this is saving a sample file

private void SaveFileToDCTM()
{
DFCLib.IDfSysObject document = (DFCLib.IDfSysObject)session.newObject("dm_document");
document.setObjectName("Test from C#");
document.setContentType("jpeg");
document.setFile("d:\\temp\\f0.jpg");
document.save();
document.link(DOCBASE_FOLDER);
document.save();
}

There are two ways to update the attributes (metadata).

  1. Use the document.setString(string attributeName, string attributeStringValue)
  2. Use DQL query

Here's the snippet for DQL query, you need to palce this after document.save():

DFCLib.IDfQuery q = clientX.getQuery();
q.setDQL("update bdo_archives_ocav object set " +
" bdo_ocav_branch_code = '" + branch_code + "', " +
"set bdo_ocav_check_number = '" + check_number + "', " +
"set bdo_ocav_amount = '" + amount + "', " +
"set bdo_ocav_account_number = '" + account_number + "', " +
"set bdo_ocav_brstn = '" + brstn + "', " +
"set bdo_ocav_clearing_window = '" + clearing_window + "', " +
"set bdo_ocav_scanned_by = '" + scanned_by + "', " +
"set bdo_ocav_accessed_by = '" + accessed_by + "', " +
"set bdo_ocav_xml_source = '" + fileSourceFromClient + "' " +
" where r_object_id = '" + o_id + "'");
q.execute(session, 3);

4 comments:

KuRcZaK said...

Hi,

When I try to run this code I'm getting following error:

Creating an instance of the COM component with CLSID {EFAC2D80-175B-11D2-9927-006097C27C31} from the IClassFactory failed due to the following error: 80004005.

Any ideas?

I'm running on x64 Win7

Unknown said...

Try executing your app as 32bit application.

??? said...

Hi

I am also getting the same error, the application is already x86. Tried re-installing the DFC many times but the error never goes.

Any Idea how can this be fixed?

Unknown said...

I am also getting the same error, the application is already x86. Tried re-installing the DFC many times but the error never goes.

Any Idea how can this be fixed?