How to Check Document Already exists in repository folder using DotCMIS

347 Views Asked by At

In my repository I put my documents into separate folders

What I want is when user push same document again I need to check whether that document already exists in the correspondent folder and if the document already there, then I need to increase the version of that document.

here is my work around up to now

var bookingIndex = (Folder)session.GetObjectByPath("/Root"); // the folder that contain all booking folders
var bookingReference = "REF0001"; // payload booking reference number
List<IFolder> BookingFolderArray = new List<IFolder>();

//gets all folders inside the path above ("Ex : /Root");
    foreach (ICmisObject cmisObject in bookingIndex.GetChildren()) 
    {
       if (cmisObject is IFolder) // check only for folders inside /Root
       {
       Folder folder = cmisObject as Folder;
        if (folder.Name.Equals(bookingReference)) // check for the folder has same booking reference number
        {
           BookingFolderArray.Add(folder);
           break;
        }
       }
    }

I am trying to get documents with following code segment but no success

List<IDocument> BookingDocuments = new List<IDocument>(); // holder for documents

foreach (ICmisObject cmisObject in BookingFolderArray[0].GetChildren()) // loop through children
{
  if (cmisObject is IDocument) // check only for documents
  {
    IDocument document = cmisObject as IDocument;
    BookingDocuments.Add(document);
  }
}

How can I get document inside BookingFolderArray[0]. Here I think i'm doing correct way otherwise correct me

1

There are 1 best solutions below

0
On

If you have a nodeRef of the document.

Try to get the document using nodeRef. If it returns a CmisObject it already exist, else it doesn't.