0

I am able to successfully send a file to Filenet using their API (FileNet.API.dll) v5.2.1 but when I try to retreive it, it is a 0 byte file with no content.

This is essentially using the methods found in their demo c# program that sends and receives files found here (http://www-01.ibm.com/support/docview.wss?uid=swg24028791)

The difference with my scenario is that I will have the source data already in Stream form so I don't to need convert a local file to a Stream like the demo does.

So the Following Methods are run: more or less in this order, some are repeated.

main create doc method executes

                IDocument doc = CreateDocument(stream, fnDoc.mimeType, fnDoc.docName, fnRepo.os, "Common", paRequest);
                IFolder folder = FetchFolder(fnRepo.os, "/");
                doc.Save(RefreshMode.REFRESH);
                IReferentialContainmentRelationship rcr = FileContainable(fnRepo.os, doc, folder);
                rcr.Save(RefreshMode.REFRESH);

                checkInDoc(doc);

The methods listed above are below

    public static IDocument CreateDocument(Stream stream, String mimeType, String docName, IObjectStore os, String className)
    {
        IDocument doc = null;
        if (className.Equals(""))
            doc = Factory.Document.CreateInstance(os, null);
        else
            doc = Factory.Document.CreateInstance(os, className);
        doc.Properties["DocumentTitle"] = docName;
        doc.MimeType = mimeType;

        IContentElementList cel = CreateContentElementList(stream, docName);
        if (cel != null)
            doc.ContentElements = cel;
        return doc;
    }

next one that is called is CreateContentElementList

    public static IContentElementList CreateContentElementList(Stream stream, string docName)
    {
        IContentElementList cel = null;
        if (CreateContentTransfer(stream, docName) != null)
        {
            cel = Factory.ContentElement.CreateList();
            IContentTransfer ct = CreateContentTransfer(stream, docName);
            cel.Add(ct);
        }
        return cel;
    }

Then finally CreateContentTransfer

    public static IContentTransfer CreateContentTransfer(Stream stream, string docName)
    {
        IContentTransfer ct = null;
        ct = Factory.ContentTransfer.CreateInstance();
        ct.SetCaptureSource(stream);
        ct.RetrievalName = docName; 
        return ct;
    }

At this point the length and size of ct is not there but these can be set manually so I am not sure if that matters. Also the variable stream still has content.

The doc is returned from CreateDocument

Then folder is fetched

    public static IFolder FetchFolder(IObjectStore os, String fPath)
    {
        IFolder f = Factory.Folder.FetchInstance(os, fPath, null);
        return f
    }

then

    public static IReferentialContainmentRelationship FileContainable(IObjectStore os, IContainable c, IFolder folder)
    {
        IReferentialContainmentRelationship rcr = null;
        if (c is IDocument)
            rcr = folder.File((IDocument)c, AutoUniqueName.AUTO_UNIQUE, ((IDocument)c).Name, DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
        else
            rcr = folder.File((ICustomObject)c, AutoUniqueName.AUTO_UNIQUE, ((ICustomObject)c).Name, DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
        return rcr;
    }

    public static void checkInDoc(IDocument doc)
    {
        doc.Checkin(AutoClassify.AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
        doc.Save(RefreshMode.REFRESH);
        doc.Refresh();
    }

So am I missing something, some last part to actually put the content on the server or something?

4
  • 1
    Has your stream been previously read (as in, are you at the end of your stream)? Does ACCE show that there is a ContentElement present? Commented Nov 9, 2016 at 15:37
  • Good question, I am passing it as a MemoryStream which was created by the Stream.CopyTo Method, then a GetButter is executed with the MemoryStream so I am guessing it might be at the end. Let me check that and what is ACCE? Commented Nov 9, 2016 at 16:08
  • That was it, the position of the stream was at the end, set it to zero before: IContentTransfer.SetCaptureSource(stream); was called Commented Nov 9, 2016 at 16:23
  • ACCE is the Admin tool that is used to work with FileNet (it replaced FEM as of FileNet CPE 5.2.1). If you are the FileNet admin, you could use ACCE to double check problems like the one you encountered here. Glad to see you have it figured out! Commented Nov 23, 2016 at 18:42

1 Answer 1

0

When calling ct.SetCaptureSource(stream); the Stream should be unread (or perhaps the position of the Stream reset), so that the API can capture the desired file.

If the position of the Stream is at the end of the Stream, you will not end up sending anything to the IContentTransfer object, resulting in a ContentElement containing 0 bytes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.