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

How can I determine if I'm in the List or Document library and I'm not on some page that is inside the document library?

For example if im on the page which is located in the pages and I do:


I will get a list Pages. So how can I determine?

share|improve this question
up vote 1 down vote accepted

If you have a SPContext.Current.ListItem and the url of that is the same as the url of the Page (without query parameters), then you're on a page inside a document library.

If not and you have a SPContext.Current.List then you're on a list or on a list item

share|improve this answer
hmm, but is there a more proper way to determine where i'm located? – Shkipper Oct 10 '12 at 9:31
I think solution given by Per is the most proper way to achieve this, if you need to distinguish between which type of list (i.e generic list, doc lib, discussion board) then use BaseType property of list which returns SPBaseType enum – Diptarag Oct 10 '12 at 12:40

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.