jeudi 8 janvier 2015

SharePoint 2010 Client Object Model - 401 on SubSite but not root



I am trying to use the CSOM to access data from a root site, then loop through its subsites to get into files that are stored in its lists. When I go to create the ClientContext, it works fine with the root URL, but when I use one of the subsites' URL's, I get a 401 when I hit ExecuteQuery().



using (var clientContext = new ClientContext(rootURL))
{
Console.WriteLine("Establishing connection...");

var userName = System.Configuration.ConfigurationManager.AppSettings["userName"];
var domain = System.Configuration.ConfigurationManager.AppSettings["domain"];
var password = System.Configuration.ConfigurationManager.AppSettings["pwd"];
var credentials = new NetworkCredential(userName, password, domain);
clientContext.Credentials = credentials;

_clientContext = clientContext;

var spContext2 = new SharePointClientDataContext(clientContext);

ClientContext newContext = new ClientContext(subsiteURL);
var allLists = newContext.Web.Lists;
newContext.Load(allLists);
newContext.ExecuteQuery();

try
{
...


The code fails at newContext.ExecuteQuery(). Any ideas why I would run into 401's at the subsite level, but not the root level?


It is also worth noting that this DOES work locally, but I am currently trying to run this from my host OS to access files from my VM.








0 commentaires:

Enregistrer un commentaire