首页 > 解决方案 > C#如何使用反射调用clientContext.Web.Lists.GetByTitle(documentLibrary)?

问题描述

我是 C# 新手,我想知道如何通过反射调用下面的代码。

ClientContext clientContext = new ClientContext(siteURL);
List documentList = clientContext.Web.Lists.GetByTitle(documentLibrary);

它依赖于Microsoft.SharePoint.Client.dllMicrosoft.SharePoint.Client.Runtime.dll

我能够创建 clientContext 对象。但是,我无法调用另一部分,即,

Web.Lists.GetByTitle(documentLibrary);

下面是我创建clientContext的代码。

        Type clinetContext = null;
        foreach (Type type in sharePointClientTypes)
            if (type.FullName.Equals("Microsoft.SharePoint.Client.ClientContext"))
            {
                clinetContext = type;
                break;
            }

        ConstructorInfo constructorInfo = clinetContext.GetConstructor(new[] { typeof(string) });
        object context = constructorInfo.Invoke(new string[] { siteURL });

谁能帮我!!

标签: c#sharepointdllreflection

解决方案


试试用这个

Web web = clinetContext.Web;
clinetContext.Load(web);
web.Context.ExecuteQuery();
List documentsList = web.Lists.GetByTitle(documentLibrary);
clinetContext.Load(documentsList);
web.Context.ExecuteQuery();

推荐阅读