[英]C# Application to upload file to SharePoint with MFA
我正在创建一个 Windows 表单应用程序以将数据插入 MSSQL,但还将用户选择的文件上传到 SharePoint。 我尝试使用下面的代码,但是由于我的服务帐户没有解除多重身份验证 (MFA),我遇到了一些严重的问题。 IT在这件事上非常坚定。
/*string SiteUrl = "https://company.sharepoint.com/sites/mySite";
string DocumentLibrary = "Documents";
string FileName = @chkAttach1.Text.ToString();
string CustomerFolder = "Application Test";
string Username = "testuser";
string Password = "123";
foreach (char c in Password)
{ securePassword.AppendChar(c); }
var olCred = new SharePointOnlineCredentials(UserName, securePassword);
using (ClientContext cContext = new ClientContext(SiteUrl))
{
cContext.Credentials = olCred;
Web web = cContext.Web;
FileCreationInformation newFile = new FileCreationInformation();
byte[] FileContent = System.IO.File.ReadAllBytes(FileName);
newFile.ContentStream = new System.IO.MemoryStream(FileContent);
newFile.Url = System.IO.Path.GetFileName(FileName);
Microsoft.SharePoint.Client.List docLib = web.Lists.GetByTitle(DocumentLibrary);
Microsoft.SharePoint.Client.Folder uplFold = docLib.RootFolder.Folders.Add(CustomerFolder);
uplFold.Update();
Microsoft.SharePoint.Client.File uplFile = uplFold.Files.Add(newFile);
cContext.Load(docLib);
cContext.Load(uplFile);
cContext.ExecuteQuery();
}
所以很明显上面的方法是行不通的。 与 IT 人员交谈时,他建议我使用 API,但我很难在线找到示例代码以使用用户当前的凭据将文件上传到 SharePoint。
有什么建议吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.