Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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

 
discard

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.