Im trying to get the listItemId based on the Document-ID of a item in the SharePoint Library.
By Document-ID I mean the ID that is automatically assigned to a document when it is uploaded to sharePoint.
I have already successfully retrieved the driveItemId using the Document-ID. This is what the method looks like:
public async Task<string> GetDriveItemIdByDocIdAsync(string driveId, string docId)
{
try
{
var query = $"Dokument-ID:{docId}";
var results = await _graphClient.Drives[driveId].SearchWithQ(query).GetAsSearchWithQGetResponseAsync();
if (results.Value.Count == 1)
{
_logger.Info($"Found one document with documentId '{docId}' in drive '{driveId}'.");
return results.Value.FirstOrDefault().Id;
}
else if (results.Value.Count == 0)
{
_logger.Info($"No document with documentId '{docId}' found in drive '{driveId}'.");
throw new Exception($"No document with documentId '{docId}' found in drive '{driveId}'.");
}
else
{
_logger.Error($"More than one document with documentId '{docId}' found in drive '{driveId}'. Returning the first item with driveItemId == '{driveItemId}'");
return results.Value.FirstOrDefault().Id;
}
}
catch (ServiceException ex)
{
_logger.Error($"Error while trying to get last version of item with documentId '{docId}' in drive '{driveId}'. Exception: '{ex}'");
throw;
}
I need the listItemId to later read out the checkInComments of the different versions of the ListItem, as far as I know this is only possible via Lists, and not via Drives.
You do not need to answer directly with the C# SDK implementation, an https request is also sufficient. Thanks for your help
2
Answers
driveItem has a relationship to listItem, so you should be able to access listItem and it’s id this way
C#
To get the SharePoint ListItemId, you can make use of below Microsoft Graph API query:
Posting details proof of work @user2250152
As you have DriveItemID you can pass it to get the list item ID
You can make use of select to fetch only the ID:
And use the below code:
The list item ID is fetched: