Please see the code below. This is my initialization:
string siteUrl = "https://(*company domain*).sharepoint.com/sites/BankGuaranteeManagement/";
string documentLibrary = "BG Docs";
string fileName = VIEWSTATE_MAIN_FILE_NAME;
string customerFolder = "Bank Guarantees";
string userNameSP = "bgmfileuser@company.com";
string passwordSP = "hs#29n#$";
This is the fileupload code:
#region ConnectToSharePoint
string serverRelativeURL = "";
var securePassword = new SecureString();
foreach (char c in Password)
{ securePassword.AppendChar(c); }
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
var onlineCredentials = new SharePointOnlineCredentials(Login, securePassword);
#endregion
#region Insert the data
using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = onlineCredentials;
Web web = clientContext.Web;
List libraryList = clientContext.Web.Lists.GetByTitle("Documents");
Folder folder = libraryList.RootFolder;
clientContext.Load(folder, f => f.ServerRelativeUrl);
clientContext.ExecuteQuery();
serverRelativeURL = folder.ServerRelativeUrl;
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, serverRelativeURL + "/" + System.IO.Path.GetFileName(filePath), fs, true);
}
#endregion
}
catch (Exception exp)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(exp.Message + Environment.NewLine + exp.StackTrace);
}
On clientContext.ExecuteQuery, I am getting the following error:
{"The sign-in name or password does not match one in the Microsoft account system."}
Some points worth mentioning:
The ID being used in credentials has MFA disabled.
The ID being used is part of the Active directory.
I can login into portal.office.com using the same ID and password. So, no issues there.
.Net version is 4.6
Latest Sharepoint dll is installed and added.
I went through all materials on internet but cannot figure this ont out. Any help will be useful. Thanks.