views:

35

answers:

1

I have a MasterPage that I am deploying to a SharePoint 2007 server. I am using a feature and a wsp to do the deployment. After deployment, my new masterpage isn't available to select and use for my site. Then, if I activate my feature, I am able to select my master page. But, when I deactivate my feature (or even retract the solution and delete it from SharePoint), the master page is still available for selection and all of the other files that were part of my feature/solution are still on SharePoint. So, is there any way to remove the master page from being available when my feature is deactivated, and then if it gets activated again, have it be available again?

Hope this makes sense, thanks.

+2  A: 

SharePoint doesn't by default clean up files deployed as part of a feature activation.

In order to remove the master page and other associated files you'll need to write a feature receiver for your feature, implement the FeatureDeactivating method, and remove your files using object model code instead of CAML. MSDN document for feature receivers is here, and there are blog examples of writing feature receiver code all over the web.

Bear in mind that in order to remove your master page you'll first need to make sure you reset the master page for all sites in the site collection to the default/another available master page. You'll also want to be careful not to remove resource files (CSS, images, etc.) that are shared among master pages or page layouts.

OedipusPrime
Thanks, I was thinking I might have to do that, but my concern was what would happen when I reactivate the feature. Will the files get put back if I reactivate the feature?
TehOne
Yes everytime you activate the feature, the files will be provisioned again (unless they already exists). But remember that if you delete the files using a featureReceiver then any modifications (done using SharePoint Designer) are lost
Per Jakobsen
Thanks for the help guys. Maybe there is a date stamp for last modified I can use to help me decide if I should delete the files using the FeatureReceiver.
TehOne