1

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.

2 Answers 2

2

how about following msdn? try using ClaimClientContext.GetAuthenticatedContext instead

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

            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);
            }
        }

http://msdn.microsoft.com/en-us/library/hh147177(v=office.14).aspx

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:

http://blogs.technet.com/b/speschka/archive/2010/06/04/using-the-client-object-model-with-a-claims-based-auth-site-in-sharepoint-2010.aspx

EDIT

after some digging about i did find this:

https://stackoverflow.com/questions/11295953/claim-auth-from-adfs

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:

http://jwillmer.de/blog/2013/01/04/sharepoint-online-with-adfs-authentication/

his solution :

https://github.com/jwillmer/SharePointAuthentication

3
  • its asking for username and password.. not authenticate window user Commented Apr 11, 2013 at 11:42
  • ammended the answer
    – Ali Jafer
    Commented Apr 11, 2013 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. Commented May 14, 2013 at 12:58
1

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

Platform Target: (Any CPU)

or

Platform Target (x64)

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

For setting permissions on ClientContext:

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

or

CNX.Credentials = CredentialCache.DefaultCredentials;

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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