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
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:
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 :
-
its asking for username and password.. not authenticate window user Commented Apr 11, 2013 at 11:42
-
-
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
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
-
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
-