0

I am getting following error

"The remote server returned an error: (401) Unauthorized."

While I'm trying to read a website hosted in SharePoint. I have tried following code to access my SharePoint site via my C#.

String Id="xyz.onmicrosoft.com";
String pass="Password";
SecureString password = new SecureString();
            foreach (char ch in pass)
                password.AppendChar(ch);
            Uri uri = new Uri("https://mydomain.sharepoint.com/sites/parts/");
            using (var context = new ClientContext(uri)) 
            {
                context.Credentials = new SharePointOnlineCredentials(Id,password);
                Web web=context.Web;
                context.Load(web, w => w.Title);
                context.ExecuteQuery();
                System.Console.WriteLine("Web Title");
                System.Console.WriteLine(web.Title);
            }

I didn't get to know whats wrong with this code. I have tried some forum solutions as well but they didn't worth to resolve this error.

1 Answer 1

0

Try this:

clientContext.Credentials = new NetworkCredential("username", "password", "domain");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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