SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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,


share|improve this question
up vote 2 down vote accepted

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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.