I wrote a simple code in CSOM to get web title. Hope code is fine. When I execute my application I got an exception from my third line (clientContext.Credentials = new SharePointOnlineCredentials("Domain\\Username", SecurePassword);)

Username argument is invalid

Any idea to solve this issue? Thanks in advance.

using (var clientContext = new ClientContext("http://siteURL"))
    SecureString SecurePassword = GetSecureString("password");
    clientContext.Credentials = new SharePointOnlineCredentials("Domain\\Username", SecurePassword);
    Web web = clientContext.Web;
    webSite => webSite.Title);
  • 1
    your tag says SharePoint-enterprise, while your code has SharePointOnlineCredential. What actual version of SharePoint you are using? SPO or SP? Jun 22, 2017 at 12:01
  • I use CSOM. Tag has been edited Jun 22, 2017 at 12:05
  • 1
    I guess you are working with SharePoint Online? Jun 22, 2017 at 12:07

1 Answer 1


The solution is very simple and clear.

While passing credentials do not use Domain name along with username. You just need to use Username.

So your code will be like:

clientContext.Credentials = new SharePointOnlineCredentials("Username", SecurePassword);

If it is SharePoint On-Prem then SharePointOnlineCredential is not required.

In such case you should use:

NetworkCredential _myCredentials = new NetworkCredential("user", "password", "domain"); // While domain will be your site url
NetworkCredential _myCredentials = new NetworkCredential(@"domain\user", "password");

and then pass credential as

clientContext.Credentials = _myCredentials;

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.