1

For developing with the SharePoint REST APIs using JavaScript I always use PnPjs because it's an easy way of getting data from SP.

PnPjs is a collection of fluent libraries for consuming SharePoint, Graph, and Office 365 REST APIs in a type-safe way.

Source: pnp.github.io/pnpjs

My question is now can I use a NuGet library that does the same in .NET (but without the thenable promises of course)?

I'll access SharePoint lists using a console application written in C#.

I've searched for alternatives but didn't find anything that looks good. The only thing I find is to write it like code below:

using Newtonsoft.Json;  
using Newtonsoft.Json.Linq;  
  
namespace REST  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("Site URL/_api/web/lists/getByTitle(List Name')/items");  
          
            endpointRequest.Method = "GET";  
            endpointRequest.Accept = "application/json;odata=verbose";  
            NetworkCredential cred = new System.Net.NetworkCredential("username", "password", "domain");  
            endpointRequest.Credentials = cred;  
            HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();  
            try  
            {  
                WebResponse webResponse = endpointRequest.GetResponse();  
                Stream webStream = webResponse.GetResponseStream();  
                StreamReader responseReader = new StreamReader(webStream);  
                string response = responseReader.ReadToEnd();  
                JObject jobj = JObject.Parse(response);  
                JArray jarr = (JArray)jobj["d"]["results"];  
                foreach (JObject j in jarr)  
                {  
                    Console.WriteLine(j["Title"]+" "+j["Body"]);  
                }  
                  
                responseReader.Close();  
                Console.ReadLine();             
            }  
            catch (Exception e)  
            {  
                Console.Out.WriteLine(e.Message); Console.ReadLine();  
            }       
        }  
    }  
}

Source: C# corner

1

1 Answer 1

1

You can use pnp even with .NET.

If you want an alternative you can use CSOM, the .NET version of JSOM

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.