I have a sandboxed solution with these items:

  • A module
    • Elements.xml (ElementManifest)
    • HelloWorld.txt
  • Package
    • MyPackage-1.0.1
  • A feature
    • Scoped for site

In addition the solution is set to Include Assembly = False.

I want this solution to be 'upgradable'.
When end user upload a new version of my WSP they should be able to click 'Upgrade' and the files are renewed, and the Elements.xml updated.
If I change package name (For example from MyPackage-1.0.1 to MyPackage-1.0.2) the solution is upgradable, but files are not changed.


So far I have come by two different ways to do this, the first is a hack and the other is a hack.

Hack 1

Use Client Object Model to delete the files. I do not have a good example of how to trigger the script (could be done from listening to the "Upgrade" button), but deleting the files is quite easy:

var ctx = new SP.ClientContext();

Hack 2

It does seem that Elements.xml is updated, so it is possible to inline the whole script into this file. This could be added to Elements.xml with a build script or similar, as one would probably not want to write JavaScript or CSS directly in Elements.xml.

  • What files are not changed? HelloWorld.txt is not updated?
    – James Love
    Sep 12, 2012 at 12:23
  • As well as my Elements-file, (CustomAction). I have thought about GhostableInLibrary/Ghostable, but it didn't seem to make a difference, but perhaps it will only work first time when done correctly. I removed the files with PS. Also by my understanding Ghostable/GhostableInLibrary would be kind of strange on a sandboxed solution where file system is restricted anyway, but...
    – eirikb
    Sep 12, 2012 at 12:59
  • After you upgrade the solution in the gallery, are you going to Site Collection Features and deactivating then activating? Nov 14, 2012 at 16:37
  • No, I click Upgrade. But I have tried that also, as well as remove/add.
    – eirikb
    Nov 14, 2012 at 16:40

3 Answers 3


Module files are indeed a problem to update or overwrite. If I understand you correctly, this is the problem you are facing? That, after deploying a newer .wsp, the old files are still present and not overwritten?

The basic issue is that module files remain when the feature containing the module is disabled or uninstalled. To resolve this, I got into the habit of manually cleaning up:

// When we deactivate the feature, we need to delete the module
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    using (SPSite spSite = properties.Feature.Parent as SPSite)
        using (SPWeb web = spSite.RootWeb)
                SPFile file = web.GetFile("MyModule");
            catch { } //sue me

This is made easier by the fact that, by default, all your module files will be gathered in one folder. So you just need to delete the folder. This solves the problem whenever you can deactive the existing module before deploying the new one, and frankly is a good habit in itself in my opinion.

Upgrading is more annoying. You are deploying a .wsp that wants to deploy files that are already present on the system. I recall trying that and I remember having to use the IgnoreIfAlreadyExists argument to make it overwrite existing files, which goes something like this in your elements.xml:

<File Path="MyModule\myfile.txt" Url="MyModule/file.txt" IgnoreIfAlreadyExists="FALSE" />    
  • Thanks for the answer, but the whole point about the question is to not have a DLL, hence your example code can not exist. And the scenario is basically for upgrade, not deactivate/activate. I must admit I have not tried IgnoreIfAlreadyExists, but I did not think it would help in my case.
    – eirikb
    Nov 14, 2012 at 16:39

A site collection administrator upgrades a sandboxed solution by installing a new sandboxed solution package (.wsp file) that has the same solution ID as the existing sandboxed solution but a different hash code.

If the sandboxed solution contains any Features, feature upgrade actions are also processed: During upgrade, the Feature definitions for the existing solution are compared with the Feature definitions for the new solution. Existing Feature definitions are upgraded on the site. All new Feature definitions are activated on the site. (Incoming requests for the sandboxed solution fail during the upgrade process.)

Installing, Uninstalling, and Upgrading Sandboxed Solutions in SharePoint 2010

  • I guess you mean that the my feature will be upgraded (and then my module referenced in that) if I change the feature definition? Well I tried setting a feature version Open feature -> Version ->, but my Elements.xml did not seem to be updated (CustomAction). Also I'm relying on solution gallery in Site Settings so anyone with SPSite (Site collection) permissions should be able to upgrade. The "Upgrade" button works when I change Package name, just nothing happens
    – eirikb
    Sep 12, 2012 at 12:58
  • I'm having this same problem, so if you've solved it, please let me know.
    – Geeky Guy
    Jul 22, 2013 at 18:29

You can use ReplaceContent attribute in xml file

<File Path="path\path...." Url="something/something.txt"  
ReplaceContent="TRUE" IgnoreIfAlreadyExists="TRUE" />

ReplaceContent set to TRUE will overwrite content of particular file.




SharePoint ReplaceContent="TRUE"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.