locked
How to connect to Cloud Sharepoint and get the response from the page created in Sharepoint Site in ASP.NET Core RRS feed

  • Question

  • User2056817590 posted

    In ASP.NET Core ,How to connect to Cloud Sharepoint and get the response from the page created in Sharepoint Site 

    Friday, April 9, 2021 5:47 AM

All replies

  • User2056817590 posted

    The following code was used to connect to the sharepoint with the credentials, but I'm not getting any response 

    HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(finalPath);
                endpointRequest.ContentType = "text/xml; encoding='utf-8'";
                endpointRequest.Credentials = GetCredentials(ciphertextSP_User, ciphertextSP_PW);
                endpointRequest.Method = "GET";
                endpointRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
                endpointRequest.Accept = "application/json;odata=verbose";
                HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();

    public SharePointOnlineCredentials GetCredentials(string userName, string password)
            {
                var securePassword = new SecureString();
                foreach (var ch in password) securePassword.AppendChar(ch);
                return new SharePointOnlineCredentials(userName, securePassword);
            }

    Friday, April 9, 2021 6:53 AM
  • User753101303 posted

    Hi,

    And what happens when this code runs? Which endpointResponse .StatusCode do you have for now?

    Not directly related and keep using that if you prefer but https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-5.0 is a more modern option. Depending on what exactly you are trying (what will do you do with the markup of this page ?) to do you also have https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index

    Friday, April 9, 2021 7:11 AM