I have requirement that Provider hosted app is in in http://localhost:1234/site1 for example

and I need to get the list items from the list in http://localhost:1234/site2

Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);

using (var clientContext =  TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, Request.LogonUserIdentity))
    List list =                     clientContext.Web.Lists.GetByTitle("ListofSiteCollection2");
    Microsoft.SharePoint.Client.ListItem item = list.GetItemById(1);

Thanks in Advance

  • Have you tried? What's the issue here? You don't know how? Is it not working? We need more info.
    – wjervis
    May 7, 2015 at 14:06
  • I gave 'web', 'site collection' level permission to that app
    – user41938
    May 7, 2015 at 14:09
  • It is not working I deployed app to one site collection, I specifing list of another site collection to get the data. It is saying "List is unknown"
    – user41938
    May 7, 2015 at 14:13
  • any information required
    – user41938
    May 7, 2015 at 14:20
  • Put your code in your question.
    – wjervis
    May 7, 2015 at 14:45

1 Answer 1


Your code is attempting to read the list from the host web, not from the other site collection. You need to create another ClientContext for the other site collection, and use it to get the list object.

var site2Ctx = new ClientContext("http://localsite:1234/site2");
    var list = site2Ctx.Web.Lists.GetByTitle("list display name");
    // do whatever you need to do
} finally 
  • I need create one more client context to get the host web list right ?
    – user41938
    May 7, 2015 at 14:56
  • Yes, your current code will work for the list on the host web.
    – wjervis
    May 7, 2015 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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