2

I'm trying to retrieve a document by its "_dlc_DocId" and I tried the suggestion at CSOM get document by ID but I end up with nothing (my "items" object is empty and I am sure my _dlc_DocId is correct).

In my case I have a root folder, and document sets (folders) within that folder. The files I'm looking for are within the document sets (sub-folders). Is there a way to retrieve a document by Id using a url (library path + ID)? Just looking for a more direct way other than brute force (iterating over each sub-folder, loading the files for each folder, and then iterating over the files for an ID match).

2
  • YOu can use CAML query to get document by id. Commented Sep 16, 2016 at 17:24
  • Right, I tried that as stated in my first sentence but it doesn't seem to be able to find my document, and I'm wondering if it's because it fails to look in sub-folders.
    – Jeremy
    Commented Sep 16, 2016 at 18:03

2 Answers 2

0

Try to using below caml query,

camlQuery.ViewXml = "<View><Query><Where><And><Eq><FieldRef Name='_dlc_DocId' /><Value Type='Text'>Your_dlc_DocId</Value></Eq><BeginsWith><FieldRef Name='ContentTypeId' /><Value Type='ContentTypeId'>0x0120</Value></BeginsWith></And></Where></Query></View>"

Folder Content Type ID starts with 0x0120.

2
  • Yes, this is exactly the solution I tried previously but the result of my "getItems(query)" is empty after running this query. Do you have the file in sub-folders on your site?
    – Jeremy
    Commented Sep 16, 2016 at 20:15
  • I have updated my answer..check it. Commented Sep 16, 2016 at 20:46
0

The CAML query needs to be recursive to query items in folders:

<View Scope='Recursive'>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name='_dlc_DocId' />
                <Value Type='Text'>UNIQUEID</Value>
            </Eq>
        </Where>
    </Query>
</View>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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