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

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:

SPContext.Current.List 

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

share|improve this question

1 Answer 1

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

 
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.