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?

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() 
  • 1
    option 2 is working, THX! – maartenvdv Sep 30 '14 at 12:26

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.