更新时间:2021-12-20 22:32:47
您可以使用PnP CSOM核心的 GetAppOnlyAuthenticatedContext
方法.
You can use the GetAppOnlyAuthenticatedContext
method of PnP CSOM core.
之后,您可以使用以下代码:
After that you can use the code as below:
string siteUrl = "https://xyz.sharepoint.com/sites/MyList/";
string clientId = "<client-id>";
string clientSecret = "<client-secret>";
using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl,clientId,clientSecret))
{
Web oWebsite = clientContext.Web;
ListCollection collList = oWebsite.Lists;
clientContext.Load(collList);
clientContext.ExecuteQuery();
}
要添加PnP CSOM核心,请转至项目参考>管理nuget程序包.
To add PnP CSOM core, go to your project references > manage nuget packages.
添加SharePointPnPCoreOnline程序包.
Add the SharePointPnPCoreOnline package.