2

I would like to add a Site template (WSP) to the solution gallery and activate it. TO this, I am using a feature which adds the file but it does not activate and it it looks like just a file that it does not recognise. What could be wrong with my code?

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        try
        {
            SPWeb web = properties.Feature.Parent as SPWeb;
            SPWeb rootweb = web.Site.RootWeb;

            SPDocumentLibrary solutionGallery = (SPDocumentLibrary)rootweb.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
            SPFile file = solutionGallery.RootFolder.Files.Add(@"Meeting Template.wsp", File.ReadAllBytes(@"Meeting Template.wsp"));
            SPUserSolution solution = rootweb.Site.Solutions.Add(file.Item.ID);

            rootweb.Features.Add(new Guid("850ECEC2-2D5E-4661-AC78-F133D782561C"), false, SPFeatureDefinitionScope.Site);

        }
        catch (Exception ex)
        {
            ILogger logger = new ULSLogger();
            logger.LogError(ex.Message, ex);
        }

    }

This is my first time trying this out. I put the actual wsp in a Module called Solutions.

Please assist.

1
  • Why not add it with powershell?
    – Remko
    Commented Nov 4, 2013 at 11:34

1 Answer 1

1

Add file.Update method to your solution e.g.

 SPFile file = solutionGallery.RootFolder.Files.Add(@"Meeting Template.wsp", File.ReadAllBytes(@"Meeting Template.wsp"));
 file.Update();
 SPUserSolution solution = rootweb.Site.Solutions.Add(file.Item.ID);

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.