1

One of the users of a C# app I work on is getting the error "User cannot be found" when the app tries to read the following fields from a SPO file:

context.Load(csomFile,
    f => f.CheckOutType,
    f => f.CheckedOutByUser,
    f => f.ModifiedBy,
    f => f.TimeCreated,
    f => f.TimeLastModified);
context.ExecuteQuery();

Any ideas why this error is occurring or what can be done about it? I am using the latest SharePoint Online CSOM (16.1.8316.1200).

0

2 Answers 2

0

Try to follow the steps below.

1.Create a console application project.

2.Install the SharePoint Online CSOM library using NuGet.

Install-Package Microsoft.SharePointOnline.CSOM -Version 16.1.8316.1200

3.Write the code like below to check if it works.

string siteUrl = "https://tenant.sharepoint.com/sites/lz";
var login = "[email protected]";
var password = "***";
var strServerRelativeURL = "/sites/lz/DL/MyTest.xlsx";

ClientContext context = new ClientContext(siteUrl);
var securePassword = new SecureString();
foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials(login, securePassword);

File csomFile=context.Web.GetFileByServerRelativeUrl(strServerRelativeURL);
context.Load(csomFile,
    f => f.CheckOutType,
    f => f.CheckedOutByUser,
    f => f.ModifiedBy,
    f => f.TimeCreated,
    f => f.TimeLastModified);
context.ExecuteQuery();          
Console.ReadLine();

If the code still not works, check if the file checked out, and check whether the checked out user and modified user are SharePoint Online users or not.

0

I discovered the user had been using the Microsoft Migration Tool for SharePoint Online. When files were uploaded using the Upload menu item from the browser, the problem did not occur. So it seems to definitely be related to some invalid user account. I was able to reproduce the issue using the migration tool as well.

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.