biconix on Thu, 03 Jan 2013 03:29:56
(I am a CRM developer and have very litle expereince with Sharepoint development)
I am writing a CRM plugin that needs to update a List in Sharepoint. the application will not run an a Sharepoint Server but in IIS. Thus there is no user interface.
I am able to view and edit the list in a browser but I am not able to retreive the list programatically. I get an error: The remote server returned an error: (403) Forbidden
The code is very simple at this point:
using (ClientContext context =
credentials = new System.Net.NetworkCredential(USER, PASSWORD, DOMAIN);
context.Credentials = credentials;
List list = context.Web.Lists.GetByTitle(SPLIST);
context.ExecuteQuery(); <= error occurs here
// Now update the list.
I probably should point out that the site uses ADFS, but I am able to login using Windows Authentication (via browser).
WHat am I leaving out that is preventing me from retreiving the list?
Gnanasekhar on Thu, 03 Jan 2013 10:23:11
a small example to get the latest list item using ClientContext,
string oldDocFile = string.Empty;
string newDocFile = string.Empty;
string uri = "http://SPUrl";
using (ClientContext clientContext = new ClientContext(new Uri(uri)))
// clientContext.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("username", "password", "domain");
clientContext.Credentials = cred;
// SPDashBoardBL objSPDashboardBal = new SPDashBoardBL();
Web web = clientContext.Web;
// Log Entry
List list = web.Lists.GetByTitle("ListName");
CamlQuery query = new CamlQuery();
query.ViewXml = @"<View><Query><OrderBy><FieldRef Name='Modified' Ascending='True' /></OrderBy></Query></View>";
ListItemCollection listItems = list.GetItems(query);
clientContext.Load(listItems, li => li.Include(i => i["Title"], i => i["Modified"], i => i["FileLeafRef"]));
foreach (ListItem item in listItems)
oldDocFile = item["FileLeafRef"].ToString();
newDocFile = oldDocFile;
Hope this helps
manish parab on Thu, 03 Jan 2013 11:17:33
removing below lines
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(USER, PASSWORD, DOMAIN);
context.Credentials = credentials;
please let me know if it works
biconix on Fri, 04 Jan 2013 02:02:28
Thanks for your reply, but I still get the same error on the ExecuteQuery
biconix on Fri, 04 Jan 2013 02:02:44
Nope, same error
biconix on Fri, 04 Jan 2013 02:29:50
the problem with this solution is that it requires a window to popup. the application I need to write is an unattended service. there can be no user interface
Srinu Tamada on Fri, 04 Jan 2013 04:23:33
1. If you are getting 403 then current user don't have access to the particular list.
2. If the user has access and still you are not able to retrive then user credentials are not recognizing at SP end.
3. To retrive the data you can use list service, its simple and best way.
4. If you don't want to use list service then debug and check web url, list value and credential details to understand more.
biconix on Fri, 04 Jan 2013 04:44:57
yes, I think I will have to use the list web service. I now need to learn how to do that....
biconix on Wed, 09 Jan 2013 14:46:28
I still get the same error
Sachin Dagar on Thu, 14 Feb 2013 18:11:26
If you are still facing same issue then try this post
biconix on Fri, 15 Feb 2013 02:55:32
it turns out the problem was with ADFS. it was probably not configured properly. when they disabled ADFS everything work as expected