4

I have a requirement where I need to verify whether the list/library with given name already exists or not.

I am implementing REST API Calls from C# so this post does not help me as I am not getting error message given in this post in C# catch. I am always getting

The remote server returned an error: (404) Not Found.

error, and I can use this error message to identify whether list/library exists or not

Another approach is also there to get all the list available and then iterate it and find your list name within that but this approach I can't implement as I am having large number of list/library so this approach will bring my code performance down.

So I am in search of an Ultimate REST endpoint URL using which I can directly get whether the list/library exists or not.

I referred Complete basic operations using SharePoint 2013 REST endpoints and Lists and list items REST API reference but I was unable to find such direct endpoint url.

So if you have gone through this requirement then please suggest an proper approach or guideline.

I can't use CSOM or SSOM.

5

You can filter lists by title using odata and count results. url pattern:

http://{your_site}/_api/Web/Lists?$filter=title eq '{your_list_title}'
  • 1
    Feeling laughing to myself. how can I miss this simple approach. Thanks man, now I am able to identify my requirement. – Aakash Maurya Jul 8 '16 at 10:31
  • 1
    Will this work for SharePoint 2010 also? – Aakash Maurya Aug 1 '16 at 9:04
  • 1
    In SP2010 you have odata 2.0 endpoint: http://{your_site}/_vti_bin/listdata.svc/{your_list_name} So you have to check response status – donMateo Aug 1 '16 at 9:24
1

You can also use PnP JavaScript library, which is open source and developed using SharePoint REST API.

To check the list, use the below snippet,

$pnp.sp.web.lists.getByTitle('Site Awssets').get().then(function(result) {
console.log('List Exists');
}).catch(function(err) {
console.log('List not found');
});

To know more about PnP, check the below links,

https://github.com/OfficeDev/PnP-JS-Core

http://www.ktskumar.com/2016/06/introduction-pnp-js-core-library/ https://github.com/OfficeDev/PnP-JS-Core/wiki/Install-and-Use

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.