Question

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#

Was it helpful?

Solution

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>
      <Contains>
         <FieldRef Name='PublishingPageLayout' />
         <Value Type='URL'>WebPartPage.aspx</Value>
      </Contains>
   </Where>"; 
   qry.ViewFields = @"<FieldRef Name='PublishingPageLayout' />"; 
   SPListItemCollection listItems = spList.GetItems(qry); 
} 

OTHER TIPS

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

<yoursiteUrl>/_vti_bin/listdata.svc/Pages?$select=Name,PageLayout

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

<yoursiteUrl>/_vti_bin/listdata.svc/Pages?$select=Name,PageLayout&$filter=substringof('BlankWebPartPage.aspx',%20PageLayout)%20eq%20true

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"

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top