0

I am using simple console application to pull data from a SharePoint Online list using the following code

string siteUrl = "https://MyServer.sharepoint.com/sites/MySiteCollection";
string userName = "myUsername@company.onmicrosoft.com"
var passWord = new SecureString();

foreach (char c in "myPassword") passWord.AppendChar(c);



            ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new SharePointOnlineCredentials(userName, passWord);
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                "<Value Type='Number'>10</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
            ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem);

            clientContext.ExecuteQuery();

            foreach (ListItem oListItem in collListItem)
            {
                Console.WriteLine("ID: {0} \nTitle: {1} \nBody: {2}", oListItem.Id, oListItem["Title"], oListItem["Body"]);
            }

However when I run this program I receive the following error

Cannot contact web site 'https://myserver.sharepoint.com/' or the web site does not support SharePoint Online credentials

When I put the full link of the list in the browser I can access it however when I put in the default site collection url i am getting denied access due to permissions.

Is it possible to pull data from this list if i specifically only have access to the list site or do i need access in parent site?

  • Try connecting to the site collection using App Only Authentication (Instead of using username and password you have to use Client Id and Client Secret). Reference – Jefin Mathew Jun 22 at 13:22
0

In order to connect to your SharePoint Online site, you must enable legacy authentication protocols in your tenant (set LegacyAuthProtocolsEnabled to TRUE).

To enable legacy authentication protocols, run the following commands against your SharePoint Online tenant (using PowerShell):

Connect-SPOService -URL https://XXXX-admin.sharepoint.com
Set-SPOTenant -LegacyAuthProtocolsEnabled $True

where ‘XXXX‘ is your tenant name

Note:

  • Changes may take up to 24 hours to take effect.

For more details refer to below article:

https://www.assistmyteam.com/kb/cannot-contact-web-site-https-xxxx-sharepoint-com-or-the-web-site-does-not-support-sharepoint-online-credentials/#:~:text=Cannot%20contact%20web%20site%20'https%3A%2F%2Fxxxx.sharepoint.com,not%20support%20SharePoint%20Online%20credentials&text=This%20error%20occurs%20if%20the,FALSE%20in%20your%20tenant%20settings).

| improve this answer | |
  • That seems to have resolved the issue. Thank you! – Eoin Coulter Jun 25 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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