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

I have a custom Site Definition that includes a feature that has an Event Receiver. When creating the custom site via the UI, the Event Receiver fires just fine. But when I create the same site via:

 New-SPWeb -Url http://SPServer/NewWeb -Template "CUSTOMSITEDEF#0" -Name "New Site" 

the Event Receiver doesn't fire. I saw another post and I made sure to run it in the SharePoint Management PowerShell. I'm adding the feature to the Site Definition by adding to the Configuration section of my onet.xml:

<Configuration ID="0" Name="CustomSiteDef" MasterUrl="_catalogs/masterpage/v4.master">
      <Lists />
      <Modules>
        <Module Name="CustomModule" />
      </Modules>
      <SiteFeatures>
        <!-- BasicWebParts Feature -->
        <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
        <!-- Three-state Workflow Feature -->
        <Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
      </SiteFeatures>
      <WebFeatures>
        <!-- TeamCollab Feature -->
        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
        <!-- MobilityRedirect -->
        <Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4" />
        <!-- Cusotm Feature -->
        <Feature ID="c3a62d2c-7244-406e-a279-e1fdba43994d" />
      </WebFeatures>
    </Configuration>

and the EventReceiver fires off of the ItemAdded event (when the page is created). Has anyone seen any similar issues? Should the PowerShell New-SPWeb act identically to creating a Site via the UI?

Below is my webtemp_custom.xml file:

<?xml version="1.0" encoding="utf-8"?>
<Templates xmlns:ows="Microsoft SharePoint">
  <Template Name="CustomSiteDefinitions" ID="10002">
    <Configuration ID="0" Title="Custom Team Site" Hidden="FALSE"
        ImageUrl="/_layouts/images/stts.png" Description=""
        DisplayCategory=" Sites" AllowGlobalFeatureAssociations="TRUE" >
    </Configuration>
    <Configuration ID="1" Title="Custom Blank Site" Hidden="FALSE"
        ImageUrl="/_layouts/images/stbs.png" Description=""
        DisplayCategory=" Sites" AllowGlobalFeatureAssociations="TRUE" >
    </Configuration>
  </Template>
</Templates>

Thanks, Sean

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Hmm I got exactly this working on another setup.

What permissions are you running your cmd-let with?

Make sure he has the privileges to execute the code in question (eg. full control of web application).

Also post your webtemp xml. I have seen discrepancies before, but that was when provisioning providers from webtemp xml was involved.

share|improve this answer
    
I thought you were onto something when I saw that my AllowGlobalFeatureAssociations was set to False. But I changed it to true, reset IIS and am still seeing issues. I'm running the script as administrator in the PowerShell Management console, and it's creating the sites just fine. –  Sean Regan Feb 25 '11 at 21:00
    
And below is my webtemp_custom.xml file: <?xml version="1.0" encoding="utf-8"?> <Templates xmlns:ows="Microsoft SharePoint"> <Template Name="CustomSiteDefinitions" ID="10002"> <Configuration ID="0" Title="Custom Team Site" Hidden="FALSE" ImageUrl="/_layouts/images/stts.png" Description="" DisplayCategory=" Sites" AllowGlobalFeatureAssociations="TRUE" > </Configuration> </Template> </Templates> –  Sean Regan Feb 25 '11 at 21:01
    
but are the account used for the shell owner of the site? Try using the same account you use from browser. Also please post code from event handler –  Anders Rask Feb 26 '11 at 23:59
    
FYI I figured out what the issue was here. Turns out any changes I was making weren't getting picked up unless I closed my PowerShell window and re-opened it. I knew PowerShell was loading the SharePoint assemblies from the snap-in, now I'm gonna look into what else is going on here... –  Sean Regan Mar 2 '11 at 14:40
    
oh yeah, i tried that many times as well. Dont know why i didnt think of that one X-). Found no workaround for that one, but its a good prac. to close those shells when you have done any kind of provisioning for exactly that reason –  Anders Rask Mar 3 '11 at 9:24

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.