Question

Is it possible to retrieve the ID of a list or library with a url?

For example, http://MyPortal/MySubsite/MyDocuments/Forms/AllItems.aspx

If so, please provide me with some sample code.

Many thanks,

KS

Was it helpful?

Solution

SharePoint is extremely large about the Url we pass it so even though the url isn't really to the site or to the list (but to a view) both constructor for SPSite and SPWeb.GetList accepts it:

using (var site = new SPSite(url))
  using (var web = site.OpenWeb())
  {
    var list = web.GetList(url);
    // ID is now in list.ID;
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top