.Net操作Sharepoint常用方法(3) 获取Client Context

public static ClientContext GetClientContext(Guid SPListId)
{
    ClientContext resultClientContext = null;
    OfficeDevPnP.Core.AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager();
    try
    {
        using (var clientContext = authManager.GetNetworkCredentialAuthenticatedContext(ConfigurationHelper.GetSPSiteURL(), ConfigurationHelper.GetSPUserAccount(), ConfigurationHelper.GetSPUserPassword(), ConfigurationHelper.GetDomainName())
        {
            bool listExists = clientContext.Web.ListExists(SPListId);
            if (listExists == true)
            {
                resultClientContext = clientContext;
            }
        }
    }
    catch (Exception ex)
    {

    }

    return resultClientContext;
}

 

posted @ 2020-12-23 14:42  无敌师爷IT技术Blog  阅读(230)  评论(0编辑  收藏  举报