2

What I want is this

using (Web web = lookup.ParentList.ParentWeb.Site.OpenWeb(lookup.LookupWebId))
            {
                List list = lookup.r.LookupWebId.LookupList;
                Field field = list.Fields.GetFieldByInternalName(lookup.LookupField);

but the above is implemented in 2010, I need the Parent list of Look Up column using CSOM for SharePoint Online

2

Use the below code to get the Parent List information from the Lookup field from SharePoint online,

private static void getParentListfromLookupField(string siteURL, string strListName, string fieldInternalName, string strUserName, string strPassword)
{
    try
    {

        ClientContext ctx = new ClientContext(siteURL);
        SecureString securePassword = new SecureString();
        foreach (char c in strPassword)
        {
        securePassword.AppendChar(c);
        }
        SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(strUserName, securePassword);
        ctx.Credentials = credentials;

        Web web = ctx.Web;
        List list = web.Lists.GetByTitle(strListName);

        Field fld = list.Fields.GetByInternalNameOrTitle(fieldInternalName);

        ctx.Load(fld);
        ctx.ExecuteQuery();

        string field_schemaXml = fld.SchemaXml;

        var lookupListId = XElement.Parse(fld.SchemaXml).Attributes().First(s => s.Name == "List").Value;
        List parentList = web.Lists.GetById(new Guid(lookupListId));

        ctx.Load(parentList);
        ctx.ExecuteQuery();

        Console.WriteLine(parentList.Title);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error: " + ex.Message);
    }
    Console.Read();
}
  • Please feel free to mark it as answer, if this answer helped you because it might help someone in future too :) – – Shantha Kumar Thambidurai Mar 9 '16 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.