0

I have the basic code below, which gets a file from local storage and uploads it to a folder in Sharepoint. The code below seems to work fine, except for that I am receiving an error:

The sign-in name or password does not match one in the Microsoft account system 

The code snippet:

public void UploadFile(string filePath, string targetFolder, string targetFileName) { using (var context = new ClientContext(Site)) { context.Credentials = GetCredentials(); var folder = context.Web.GetFolderByServerRelativeUrl(targetFolder); var fileCreationInfo = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(filePath), Overwrite = true, Url = targetFileName }; var file = folder.Files.Add(fileCreationInfo); context.Load(file); context.ExecuteQuery(); } } private SharePointOnlineCredentials GetCredentials() { var encryptedPassword = new SecureString(); foreach (var ch in Password.ToCharArray()) encryptedPassword.AppendChar(ch); return new SharePointOnlineCredentials(Username, encryptedPassword); } 

I am using version 16.1.6621.1200 of the Microsoft.SharePointOnline.CSM NuGet package. The application is on .NET 8.0.

I have been able to login to the Sharepoint site using the exact same Username and Password as is used in the snippet below. The same credentials are used on an older system and appear to work fine (with identical code, but on .NET Framework 4.8).

1 Answer 1

0

I found that the Password is different when authenticating with the Username on browser vs app integration. I updated the Password used in the application and it works now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.