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

I have created a module with a few files that I update & delete via spfeature. Thing is if a page layout is in use I cannot delete it and it throws an error, even when inside a try{ }catch{} . How do I test what page layout(s) being used? -C#

share|improve this question
What do you mean with "even when inside a try{}catch{} block"? The catch clause does not catch the exception?? – SPArchaeologist Mar 15 '13 at 14:47
Try{ SPFile.Delete(); } catch{ } but since the file is the page layout still being refrenced it throws an error & the disable fails to disable the feature – user13186 Mar 15 '13 at 16:14
Does the catch block re-throw the error? I am using a similar code (try deletion, fail and on the catch block log the error and add a notification for the user) inside a feature deactivation handler with no problem at all. Feature completes the deactivation - as long as in my handler I don't bubble up the error. Yes, the file will still be there after the feature deactivate, but since I notify the user that is just what I want. – SPArchaeologist Mar 15 '13 at 16:23
up vote 1 down vote accepted

To test your pages list in the Feature deactivated event you should be able to query by page layout. The following will return any pages in the "Pages" list whose page layout contains "WebPartPage.aspx".

SPList spList = spWeb.Lists.TryGetList("Pages"); 
if (spList != null) 
   SPQuery qry = new SPQuery(); 
   qry.Query = 
   @"   <Where>
         <FieldRef Name='PublishingPageLayout' />
         <Value Type='URL'>WebPartPage.aspx</Value>
   qry.ViewFields = @"<FieldRef Name='PublishingPageLayout' />"; 
   SPListItemCollection listItems = spList.GetItems(qry); 
share|improve this answer

You could do the check really easy right in the browser using the the out of the box web service listdata.svc.

Display all pages from the "Pages" list and their layouts


Display only pages from the "Pages" list using BlankWebPartPage.aspx layout


Note: If you use IE you'll want to see the raw XML not the "helpful" rss feed view. Go to Internet Options -> Content tab -> Feeds and Web Slices Settings -> Uncheck "Turn on feed reading view"

share|improve this answer
It needs to be checked as apart of the feature deactivation event reciever not manually – user13186 Mar 15 '13 at 16:18

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.