I am trying to access a list via LINQ to SharePoint that is part of a different site collection. I am able to create the DataContext object for the other site but when I try to access the DataContext.ListName property I get:

3 Answers
3

As an alternative to Ryans answer (which works great for SharePoint 2010).

As of SharePoint 2013 there's an constructor overload for DataContext with the parameter crossSiteCollection. So instead of temporarily clearing the HttpContext, add a partial class with the constructor for your DataContext (or modify your SPMetal-generated classes directly) and use that one when querying another site collection.

The reason this works is because SharePoint always creates a new SPSite and SPWeb object if this parameter crossSiteCollection is true instead of reusing SPContext.Current.Site (from HttpContext.Current, which solved it for 2010).

I was unable to find a workaround for this. As using LINQ to SharePoint across site collections is "not supported". I am then required to run the get_list function with elevated privileges when opening lists from other site collections.

Unless the current user under who this call will be made has at least read access on the target site collection, you'll always run into troubles.

If you're target site collection is running a on separate web application which has its own application pool, you'll also need to ensure that they share the same "application pool" account identity as running with elevated privileges will simply execute the current operation under the application pool identity.

For trusty cross site collection data mining, you should rely on the search service application (with a crafted search scope) or impersonate an account that has access on all target site collections.