1

I've created a Feature and I want it to be activated when installed. This is the code:

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
    SPWeb web = properties.Feature.Parent as SPWeb;
    SPWebTemplateCollection existingWebTemps = web.GetAvailableWebTemplates(1033);
    Collection<SPWebTemplate> newWebTemps = new Collection<SPWebTemplate>();        
    for (int i = 0; i < existingWebTemps.Count; i++)
    {
        if (!existingWebTemps[i].Title.ToLower().Contains("blog"))
        {
            newWebTemps.Add(existingWebTemps[i]);
        }
    }
    web.SetAvailableWebTemplates(newWebTemps, 1033);
    web.Update();

    string fID = "aeb3aa40-8a42-4577-bed2-a0e65eff8b04";
    Guid gfID = new Guid(fID);
    SPFeatureCollection featatv = web.Features;
    Boolean control = true;
    foreach (SPFeature myfeat in featatv)
    {
        if (myfeat.DefinitionId == gfID)
        {
            control = false;
        }
    }
    if (control == true)
    {
        web.Features.Add(gfID);
    }

    web.Dispose();
}

When I deploy I get the error:

Error occurred in deployment step 'Add Solution': Object reference not set to an instance of an object.

I can't understand why I'm getting this error. Any thoughts on why? Thank you!

9
  • did you find anything in event log ??
    – Sigar Dave
    Commented Mar 13, 2013 at 5:50
  • @SigarDave I searched the logs but couldn't find anything useful - the logs I saw were at (...)\15\LOGS. Am I looking in the right place? I'm new to SharePoint, please bear with me! :) In VS there's nothing besides the error message.
    – Carlos
    Commented Mar 13, 2013 at 11:26
  • Yes you are at the right place
    – Sigar Dave
    Commented Mar 13, 2013 at 11:29
  • Try this thing ,set the feature property “Always Force Install” to true. let me know the outcome
    – Sigar Dave
    Commented Mar 13, 2013 at 11:30
  • With Force Install the feature is deployed but not activated as it should be. As for the logs, what log should I look at? Thank you!
    – Carlos
    Commented Mar 13, 2013 at 14:52

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.