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 = new ClientContext(SPSITE))


                    System.Net.NetworkCredential 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?




Hemendra Agrawal on Thu, 03 Jan 2013 06:15:16


It seems that USER is not having permission to access list so have you try to open sharepoint site by login as this user? Please try and verify.

Also look at this blog, which indicate to getauthenticatedcontext method:

Let us know your result

Kranthi Kumar Amaravadi on Thu, 03 Jan 2013 07:17:03


You can also use web services to read list items

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
                //  objSPDashboardBal.Get();
                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....


Hemendra Agrawal on Fri, 04 Jan 2013 11:06:09


Then use lists.asmx web service where you can pass same network credential but this user should have at least read access in site. However above solution should also work if everything is set properly but i don't understand where is problem as we have very few details about your requirement.

Now try with SP web service by following below blog:

Let us know your result

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

Hi Biconix,

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