Hi @Thomas Lu ,
Per my research and testing, you can use the follow graph api to find ID of the file in the list:
GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{itemid}
By the way, do you want to display the check-in/check-out information directly in a SharePoint list, or do you still store the information in excel and then upload the excel to SharePoint?
I did a test using CSOM, in my test, to determine if the user exists in the list, if not, add the user and the check-in time to that list, if it exists, then add the check-out time. Here is my test code. Hope it can help you :
static void Main(string[] args)
{
var clientContext = GetonlineContext();
Web web = clientContext.Web;
List targetList = clientContext.Web.Lists.GetByTitle("ListTest");
CamlQuery oQuery = new CamlQuery();
oQuery.ViewXml = @"<View><Query><Where>
<Eq>
<FieldRef Name='name' />
<Value Type='Text'>zella</Value>
</Eq>
</Where></Query></View>";
ListItemCollection oItems = targetList.GetItems(oQuery);
clientContext.Load(oItems);
clientContext.ExecuteQuery();
ListItem oItem = oItems.FirstOrDefault();
if(oItem !=null)
{
oItem["check_x002d_outtimes"] = DateTime.UtcNow;
oItem.Update();
clientContext.ExecuteQuery();
}
else
{
ListItemCreationInformation oListItemCreationInformation = new ListItemCreationInformation();
ListItem oItemadd = targetList.AddItem(oListItemCreationInformation);
oItemadd["name"] = "zella";
oItemadd["check_x002d_intimes"] = DateTime.UtcNow;
oItemadd.Update();
clientContext.ExecuteQuery();
}
}
if not exists :
if exists:
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.