Pergunta

There is a problem with Enable-SPFeature command in case of having an event receiver in the feature. Feature Activated event is not fired. If I enable the feature manually everything works well. So, there is a workaround for this :

workaroud

In my case, the feature is scope: WEB

$web= Get-SPWeb -Site https://aaa.com

        $feature = Get-SPFeature "Guid" 
            if($feature)
            {
                $featureId = $feature.Id;
                $site = Get-SPSite $site.Url
                if(-not $web.Features[$featureId])
                {
                    $web.Features.Add($featureId);
                }
            }

error:

Exception calling "Add" with "1" argument(s): "Could not load file or assembly 'App_GlobalResources' or one of its dependencies. The system cannot find the file specified."

So any idea how can I fire the event receiver.

event receiver:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
 //get ressource value 
            ResourceManager MyResourceClass = new ResourceManager("Resources.MySite.Global", System.Reflection.Assembly.Load("App_GlobalResources"));
            string title= MyResourceClass.GetString("UserControl_Message_Title");
            string Message = MyResourceClass.GetString("UserControl_Message_Description");

using (SPWeb oWeb = properties.Feature.Parent as SPWeb)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate
                      {
                          SPList oList = oWeb.Lists["splist"];

                          SPListItem oListItem = oList.Items.Add();
                          oListItem["Title"] = title;
                          oListItem["Message"] = msg;

                          oListItem.Update();

                      });
                }
            }
Foi útil?

Solução

Is your feature assembly GACed? If not, make sure the feature assembly is located someplace where powershell can find it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top