How to add item to SharePoint list from window application using claim based authentication ? it gives 401 forbidden error. user is authenticated from ADFS server.


how about following msdn? try using ClaimClientContext.GetAuthenticatedContext instead

string targetSite = "http://SharePointServer/";
using (ClientContext CNX = ClaimClientContext.GetAuthenticatedContext(targetSite))
            //Load Libraries from SharePoint

            using (FileStream fs = new FileStream(fileName.ToString(), FileMode.Open, FileAccess.Read))

                Microsoft.SharePoint.Client.File.SaveBinaryDirect(CNX, "/" + "Shared Documents" + "/" + System.IO.Path.GetFileName(fileName.ToString()), fs, true);


if it doesnt work and still returns a 403 than it has to be an issue with ADFS not setup properly! check and refer to this:



after some digging about i did find this:


they have a similar issue to you and required authentication from adfs! the issue is its complex and so he made a quick bolg on his findings:


his solution :


| improve this answer | |
  • its asking for username and password.. not authenticate window user – Rajesh Joshi Apr 11 '13 at 11:42
  • ammended the answer – Ali Jafer Apr 11 '13 at 13:26
  • please dont just add alot of external links! Those links tend to move/die/get lost. Instead please add some examples from the external links, and then link to answer. – Anders Rask May 14 '13 at 12:58

Please make sure that your Build Configuration for your windows application is set to

Platform Target: (Any CPU)


Platform Target (x64)

in Project Properties --> Build --> General in Visual studio

For setting permissions on ClientContext:

CNX.Credentials = new NetworkCredential("user", "password", "domain");


CNX.Credentials = CredentialCache.DefaultCredentials;

Also, have you seen this blogpost? It has some helper dll that seems to be helpful

| improve this answer | |
  • its giving error because of adfs authentication. i cant get authenticated client context – Rajesh Joshi Apr 11 '13 at 9:32
  • Why do you need the client context to add an item to a list? – Robert Lindgren Apr 11 '13 at 9:36
  • because i m adding item from window application and context is authenticated from adfs – Rajesh Joshi Apr 11 '13 at 9:42
  • Can you please post some of your code so we can get an idea of your approach – Robert Lindgren Apr 11 '13 at 9:47
  • Please see my updated answer – Robert Lindgren Apr 11 '13 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.