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?

1 Answer 1

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
  • 1
    option 2 is working, THX! Commented Sep 30, 2014 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.