Sharepoint 2013 On-Premises C# CSOM Cross Site Collection List Access -


i see has sorta been asked bunch times before, examples running across not work or in javascript , need c# please.

i have farm server site collections on it, created provider hosted addin/app, when trys access lists on web launched fine! need try access lists on other webs in same farm , on same domain have example of c# code can

you can create repository method this:

public class sharepointrepository     {         public listitemcollection listtopn(string urlsite, string listname, bool ascending, string column, int rowlimit)         {             using (var context = new clientcontext(urlsite))             {                 context.credentials = credentialcache.defaultcredentials;                 list list = context.web.lists.getbytitle(listname);                  string myquery = string.format("<view><query><orderby><fieldref name='{0}' ascending='{1}' /></orderby></query><rowlimit>{2}</rowlimit></view>", column, ascending.tostring(), rowlimit);                  camlquery query = new camlquery();                 query.viewxml = myquery;                  listitemcollection collection = list.getitems(query);                  context.load(list);                 context.load(collection);                 context.executequery();                 return collection;             }         } } 

this approach uses managed csom.

and if facing problems adfs, try adding after line

context.credentials = credentialcache.defaultcredentials; 

this

context.executingwebrequest += new eventhandler<webrequesteventargs>(mixedauthrequestmethod); 

and function

void mixedauthrequestmethod(object sender, webrequesteventargs e) { e.webrequestexecutor.requestheaders.add("x-forms_based_auth_accepted", "f"); }

this basic referente: https://msdn.microsoft.com/en-us/library/office/fp179912.aspx

you should @ sharepoint app model , rest odata api.


Comments