Hello Techies--
I'm missing something important in this code snippet: First, although I'm getting a document collection when I issue the statement
IManDocuments oDocuments = (IManDocuments)docFolder.Contents -- I don't get the full set, so I must not understand what Contents really brings back when I surf through specific document folders. The second thing--I know I have a document when I'm looping through the document collection (such as it is) -- but -- I seem to be getting a null reference exception. *sigh* -- I must be doing something really silly.
BTW, the objective is this: I am trying to search the entire database for a document containiing select profile information. Once I find it, I want to return it and update some other profile info.
Thanks for your help!
Warm regards,
Paula DiTallo
------- Code Snippet ---------------------------------------------------------
public IManDocument GetDoc(IManSession user_session, IManDocumentFolder docFolder, string doc_id, string doc_version)
{
IManDocument oDoc = null;
try
{
if(docFolder != null)
{
IManDocuments oDocuments = (IManDocuments)docFolder.Contents;
foreach(IManDocument innerDoc in oDocuments)
{
Console.WriteLine("Looking at doc: '" + (innerDoc.GetAttributeByID(imProfileAttributeID.imProfileDocNum)).ToString() + "'" + " Version: " + (innerDoc.GetAttributeByID(imProfileAttributeID.imProfileVersion).ToString()) + " " + (innerDoc.GetAttributeByID(imProfileAttributeID.imProfileDescription).ToString()));
if ( innerDoc.GetAttributeByID( imProfileAttributeID.imProfileDocNum).ToString() == doc_id &&
innerDoc.GetAttributeByID(imProfileAttributeID.imProfileVersion).ToString() == doc_version.ToString())
{
if (innerDoc.ObjectType.ObjectType == imObjectType.imTypeDocument)
{
oDoc = (IManDocument)innerDoc; // This fails with "object reference not set to instance of an object"
Console.WriteLine("Found document! Details: " + oDoc.Name + " " + "Status: " + oDoc.GetAttributeByID(imProfileAttributeID.imProfileCustom3).ToString() + " " + "CR: " + oDoc.GetAttributeByID(imProfileAttributeID.imProfileCustom29).ToString());
}
}
}
}
}
catch(Exception error)
{
Console.WriteLine("Failed to get doc, here's why: " + error);
}
return oDoc;
}
Paula DiTallo - Middleware Architect/ .NET Developer
plditallo@metro-design-dev.com