1

I have one list Users on root site. and another list I'm creating using client object model in sub site.

Users list is already created. I'm try to add Users list reference in sub site list but is assigned with blank list.

Code:

List oList = clientContext.Web.Lists.GetByTitle("lst");
            List userList = clientContextRoot.Web.Lists.GetByTitle(ListName.Users.ToString());
            clientContextRoot.Load(userList);
            clientContextRoot.ExecuteQuery();var fields = oList.Fields;
            string usersLookUp = string.Format("<Field ID='{0}' Type='Lookup' Name='User' StaticName='User' DisplayName='User' ReadOnly='FALSE' List='{1}' ShowField='Title' Required='TRUE'/>", Guid.NewGuid(), userList.Id);
            fields.AddFieldAsXml(usersLookUp, true, AddFieldOptions.AddToDefaultContentType);
            clientContext.Load(fields);
            clientContext.ExecuteQuery();

Lookup field is created with blank reference of list. See image: enter image description here

Your Answer

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

Browse other questions tagged or ask your own question.