1

I have a requirement to ask user to type in the URL of the SharePoint List or library and do validation whether that is a valid list or not. The URL could be of other site collection / subsite too. What is the best way to check if its a valid list URL and how to get the list object out of it?

Note: I can use JSOM / REST only (no server side code)

Nitin Khubani
  • 354
  • 1
  • 4
  • 18

2 Answers2

0

I would try to get the list with PnP: https://github.com/SharePoint/PnP-JS-Core/wiki/Working-With:-Items

Here is the whole lists class described: https://github.com/SharePoint/PnP-JS-Core/blob/master/src/sharepoint/lists.ts

  • If the request is successful, the list exists.
  • If the request fails, the list doesn't exist (or another error occured).
engineerer
  • 171
  • 4
0

Coming up one idea like this, create 3 input box for users, one to input site/subsite url, second input type, list/libray/folder/ 3rd input list/library/folder name, then you could add logic to check the giving information with Rest API, I think this will be suitable for this use case.

Jerry
  • 3,480
  • 1
  • 10
  • 12
  • When it comes to lists, its fairly simple as you suggested. But assume that its a library inside the subsite and URL is like this https://tenant.sharepoint.com/sites/site1/subsite1/documentlibrary1/ or folder https://tenant.sharepoint.com/sites/site1/subsite1/documentlibrary1/folder1 How would we do it? – Nitin Khubani Jan 15 '19 at 09:38
  • @NitinKhubani, you could use _api/Web/GetFolderByServerRelativeUrl('folderRelativeUrl') to check if a library or library sub folder exists. https://sympmarc.com/tag/getfolderbyserverrelativeurl/ – Jerry Jan 22 '19 at 09:15
  • There is a URL and it can be a list or library. It can be in any other site collection or subsite. A list not necessarily need to have /Lists/ in it. using ListInstance module, I can even created list without /Lists/. The URL can be a Document Library or folder inside document library so there are many usecases here. above solutions seems to be fixing a single case but not the whole usecase of getting List of Library out of URL. Right? – Nitin Khubani Jan 23 '19 at 12:12
  • Coming up one idea like this, create 3 input box for users, one to input site/subsite url, second input type, list/libray/folder/ 3rd input list/library/folder name, then you could add logic to check the giving information with Rest API, I think this will be suitable for this use case. – Jerry Jan 23 '19 at 15:04
  • Yeah we ended up with the same logic :) thank you Jerry – Nitin Khubani Jan 24 '19 at 09:16
  • Glad to hear this would be helpful to you and I will edit my original post and you could Mark as answer so that it could help others who stuck with the same question in the forum. – Jerry Jan 24 '19 at 11:02