Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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:

http://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

share|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 Sharepoint 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
add comment

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

share|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
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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