Uploading document to sharepoint office 365 site using client object model

Hi All,

I am using the bellow code to upload a document to Office 365 site, first i was using client dll from 15 folder and i am not able to connect then i have installed the latest SDL for sharepoint Online and get the dll from 16 folder now i am able to run the application but when i try to connect to the server i got bad user name and password but the same password is working when i am accessing the same site using Internet explorer, please sugess, below is the code and error i got.

I have created this as a windows application

Sample Code

 using (var context = new ClientContext("https://mydomain.com/"))
    {
        var passWord = new SecureString();
        foreach (var c in "MyPassword") passWord.AppendChar(c);
        context.Credentials = new SharePointOnlineCredentials("me@mydomain.com", passWord);
        var web = context.Web;
         Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, targetfileURL, fileStream, true);
         context.ExecuteQuery();
    }

Getting error on the line "

context.Credentials = new SharePointOnlineCredentials("me@mydomain.com", passWord);

"

Error details.

---------------------------
Error!!!
---------------------------
The partner returned a bad sign-in name or password error. For more information, see Federation Error-handling Scenarios.   at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.DoPost(String url, String contentType, String body, Func`2 webExceptionHandler)

   at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.GetPartnerTicketFromAdfs(String adfsUrl, String username, String password)

   at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.GetServiceToken(String username, String password, String serviceTarget, String servicePolicy)

   at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetAuthenticationCookie(Uri url, String username, SecureString password, Boolean alwaysThrowOnFailure, EventHandler`1 executingWebRequest)

   at Microsoft.SharePoint.Client.SharePointOnlineCredentials.GetAuthenticationCookie(Uri url, Boolean refresh, Boolean alwaysThrowOnFailure)

   at Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(ClientRuntimeContext context, HttpWebRequest request)

   at Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream()

   at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()

   at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()

   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

   at SPODocumentMigration.Form1.btnupload_Click(Object sender, EventArgs e) in D:\rajan\SPODocumentMigration\SPODocumentMigration\Form1.cs:line 75
---------------------------
OK   
---------------------------

March 27th, 2015 12:48am

Hi Rajan,

Please check out the below scenarios

https://social.technet.microsoft.com/Forums/msonline/en-US/a0ed894a-dd20-4b65-beda-9d5e813b04e6/uploading-file-into-share-point-online-with-a-outlook-live-id-using-c?forum=onlineservicessharepoint

http://stackoverflow.com/questions/23473348/unable-to-authenticate-to-sharepoint-online-programmatically-with-federated-serv

Free Windows Admin Tool Kit Click here and download it now
March 27th, 2015 2:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics