I have SharePoint 2013 site mounted as a network drive. I am accessing the document library through Java code, and want to know how to get the unique Document Id that SharePoint maintains for each document.

I try to get the id for a file on a file system like this

public static final String getFileId(Path path) 
        throws Exception {
    try {
        if(path != null) {
            BasicFileAttributes basicAttributes = Files.readAttributes(path, BasicFileAttributes.class);

            // Linux file system, get file id from inode
            if(basicAttributes.fileKey() != null) {
                return basicAttributes.fileKey().toString();
            } else {
                // Windows file system, get file id via Kernel32.dll
                logger.debug("The fileKey() method returned null");
                WinBase.SECURITY_ATTRIBUTES attr = null;
                BY_HANDLE_FILE_INFORMATION fileInformation = new BY_HANDLE_FILE_INFORMATION();
                HANDLE fileHandler = Kernel32.INSTANCE.CreateFile(path.toString(), Kernel32.GENERIC_READ, Kernel32.FILE_SHARE_READ, attr, Kernel32.OPEN_EXISTING, Kernel32.FILE_ATTRIBUTE_ARCHIVE, null);
                Kernel32.INSTANCE.GetFileInformationByHandle(fileHandler, fileInformation);
                String fileId = fileInformation.nFileIndexHigh + "-" + fileInformation.nFileIndexLow;                   

                return fileId;
    } catch(Exception err) {
        throw err;

    return SCConstant.EMPTY;

The above method when run on SharePoint documents (residing on the mounted network drive), give 0 for the index high and index low, and hence for all documents fileId is 0-0. I need a way to get the document id that SharePoint uses to uniquely identify each document.

  • Do you mean JavaScript not Java? Please share your code so we can be more helpful. – Submits Aug 18 '16 at 8:43
  • I mean Java. I am using Java IO to access SharePoint files mounted as a network drive. – Puneet Aug 18 '16 at 9:00
  • Ah, in the case I'm not sure you'll be able to get the document's ID, i.e. the item ID. Unless the ID was in the document's file name. You could append the ID to the document's file name with a SharePoint workflow. – Submits Aug 18 '16 at 9:02
  • The thing about document ids is in SharePoint (support.office.com/en-us/article/…) is that even though name changes, folder changes, the id for a particular document would never change. – Puneet Aug 18 '16 at 9:04

I solved my question so I am posting an answer.

What I first did was enable Document ID feature for SharePoint. We need to go to Site Settings and under Site Collection Administration > Site collection features, we need to activate Document Id service. A scheduled job generally assigns document ids to all document existing in SharePoint.

Next we can use the endpoint /GetFileByServerRelativeUrl(filePath)/ListItemAllFields to get the document id via SharePoint REST API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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