1

Is it possible to get a list by url? Something like this.

Dim list As SP.List = ctx.Web.Lists.GetByURL("site")

If that isn't possible, is it possible to get the guId by using the page id?

maartenvdv
  • 51
  • 1
  • 10

1 Answers1

2

Option 1. Get List by Url

The below solution demonstrates how to retrieve List by its Url, it consists of two steps:

  • Get List Folder using Web.GetFolderByServerRelativeUrl by specifying List Url
  • Get List by specifying List id from Folder vti_listname property

Code:

'1 step. Get List Folder
Dim listUrl As String = "/kb/Pages/"
Dim listFolder As Folder = ctx.Web.GetFolderByServerRelativeUrl(listUrl)
ctx.Load(listFolder.Properties)
ctx.ExecuteQuery()
Dim listId As Guid = New Guid(listFolder.Properties("vti_listname").ToString())
'2 step. Get List 
Dim list As List = ctx.Web.Lists.GetById(listId)
ctx.Load(list)
ctx.ExecuteQuery()

Note: SharePoint 2013/Online is supported only

Option 2. Get List by Page Url

The following example demonstrates how to retrieve List by Page Url:

Dim pageFile = ctx.Web.GetFileByServerRelativeUrl("/kb/Pages/Welcome.aspx")
Dim pageItem = pageFile.ListItemAllFields
Dim list = pageItem.ParentList
ctx.Load(list)
ctx.ExecuteQuery() 
Vadim Gremyachev
  • 42,498
  • 3
  • 86
  • 167