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

When i retract my solution several files are not deleted including my custom master. Probably something simple but i want it deleted so that visual studio doesn't complain every time i deploy about deployment conflicts that it needs to resolve. Do i need to set something in the element.xml?

<File Path="Master_Pages\FamilyCare.master" Url="FamilyCare.master" IgnoreIfAlreadyExists="False"/>
share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

When you deploy a file to a gallery using the File CAML element, SharePoint does not automatically remove the file when you deactivate the feature (or retract the solution). Presumably this is to prevent parts of the site that rely on the presence of that file from breaking if you were to accidentally deactivate the feature.

To get around it, you should attach a feature receiver to the feature that deploys your custom master page. In the "FeatureDeactivating" event, you can take care of removing the file manually. Something like this:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
   var site = properties.Feature.Parent as SPSite;
    var gallery = site.GetCatalog(SPListTemplateType.MasterPageCatalog);

    if (gallery != null) {
        gallery.GetItemById(0).Delete();
    }
}
share|improve this answer
    
I prefer setting the old, original masterpage back as default masterpage, so before deleting, first set masterpage to i.e. v4.master. –  Ernst Wolthaus Aug 24 '11 at 9:57
add comment

If you set the Type to GhostableInLibrary, then the file will be Ghosted in the library. Thus, when you come to redeploy the solution, the file in the library will reference the physical file in the SharePoint Root directory, and will always be up to date.

share|improve this answer
    
This does not cure deployment conflicts. –  user6993 Feb 19 '12 at 0:59
add comment

Have you tried setting "IgnoreIfAlreadyExists" to TRUE? If I remember correctly, that will cause your solution to overwrite the existing file. I seem to remember thinking that it seemed backwards - what it's actually saying is 'ignore if the file already exists and overwrite it anyway'

From MSDN:

IgnoreIfAlreadyExists - Optional Boolean. TRUE to provision the view even if the file aready exists at the specified URL; otherwise, FALSE.

share|improve this answer
    
If it's set to false, it'll error. If it's True, it'll ignore and carry on. Does what it says on the tin. –  James Love Aug 23 '11 at 16:37
add comment

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.