jeudi 15 novembre 2018

C# How to invoke clientContext.Web.Lists.GetByTitle(documentLibrary) using Reflection?

I am new to C# and I would like to know how to invoke the below code via Reflection.

ClientContext clientContext = new ClientContext(siteURL);

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

It has the dependency on Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll.

I was able to create the clientContext Object. However, I am not able to invoke the other part i.e., Web.Lists.GetByTitle(documentLibrary);

Below is my code to create the 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 });

Can anyone help me!!





Aucun commentaire:

Enregistrer un commentaire