How to login to SharePoint online office 365 site using service account which does not have Email ID associated with it RRS feed

  • Question

  • Hi All,

    I have developed a console application which connects to SharePoint office 365 site and download documents from a particular Document library to system.

    The code works fine when I am using my personal account to run the code. But we can not use our personal account in other environments other than development. So we have created service account which has User ID but there is no Email ID associated with it.

    But when I am using service account to tun the code it is throwing below error :

    Microsoft.SharePoint.Client.IdcrlException was unhandled 

     Message=Identity Client Runtime Library (IDCRL) could not look up the realm information for a federated sign-in.



    Please assist.

    Thanks in advance.

    • Edited by SHD25 Wednesday, October 19, 2016 11:08 AM
    • Moved by Sjoukje ZaalMVP, Moderator Wednesday, October 19, 2016 11:18 AM Moved to the Office 365 development forum
    Wednesday, October 19, 2016 11:08 AM

All replies

  • Are you using below code to download the file? If not, can you give it a try?

    const string username = "";
    const string password = "password";
    const string url = "";
    var securedPassword = new SecureString();
    foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
    var credentials = new SharePointOnlineCredentials(username, securedPassword);
    DownloadFile(url,credentials,"/Shared Documents/Report.xslx");
    private static void DownloadFile(string webUrl, ICredentials credentials, string fileRelativeUrl)
         using(var client = new WebClient())
            client.Credentials = credentials;
            client.DownloadFile(webUrl, fileRelativeUrl);

    Regards, Sjoukje. Blog | LinkedIn | Twitter

    Wednesday, October 19, 2016 11:25 AM
  • Yes..I am using same code.
    Wednesday, October 19, 2016 2:57 PM