Hi @Broeckling,Corey
403 error usually caused by your permissions to the folder haven’t replicated correctly on the server. Please check if you have the correct permission to the folder you want to upload files by following steps.
https://sharepointmaven.com/2-ways-see-users-access-sharepoint/
After check the permission you can upload a file by following code
string userName = "******@xxxx.onmicrosoft.com";
string password = "xxx";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
using (var clientContext = new ClientContext("https://xxx.sharepoint.com/sites/test"))
{
clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
Web web = clientContext.Web;
clientContext.Load(web, a => a.ServerRelativeUrl);
clientContext.ExecuteQuery();
List documentsList = clientContext.Web.Lists.GetByTitle("Contact");
var fileCreationInformation = new FileCreationInformation();
//Assign to content byte[] i.e. documentStream
fileCreationInformation.Content = System.IO.File.ReadAllBytes(@"D:\document.pdf");
//Allow owerwrite of document
fileCreationInformation.Overwrite = true;
//Upload URL
fileCreationInformation.Url = "https://testlz.sharepoint.com/sites/jerrydev/" + "Contact/demo" + "/document.pdf";
Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(fileCreationInformation);
//Update the metadata for a field having name "DocType"
uploadFile.ListItemAllFields["Title"] = "UploadedviaCSOM";
uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();
}
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.