.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Running code after site definition site creation in a event receiver or feature receiver

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :SharePoint
Hi guys I've got a site definition which is pretty much based on STS.This is it's own sharepoint project. Let's call this project SiteDefProj. Next in another SharePoint project (same solution though). Let's call this CustomListProject. In this project I've got a feature which provisions a bunch of lists based on custom content types - this feature is a site scoped. Let's call this feature: CustomListInstances. I have added a feature receiver to this feature to execute some custom code on the lists themselves (under feature activated) In my ONET.XML (part of the SiteDefProj) I have CustomListInstances feature ID as part of my <sitefeatures>. When I do a create site I can actually step through the code and see it actually being executed but after the site is created the list instances are created but it's like the code never run or did anything. The weird part is that stepping through the code while creating a site collection using my SiteDefProj the code runs great with no errors. All lists are there and the code runs smooth. If I manually create a STS site and activate my feature everything works and the code does actually run and the effects are visible after the feature is created. Again I can actually step through it in debug. My suspicion is that there's some sort of a race condition in the CREATE SITE functionality where maybe the web or site collection hol

View Complete Post

More Related Resource Links

Why feature with event receiver doesn't activate properly after site provisioning?



I have defined feature with event receivers for my document library and for users List .

I try to activate my feature in onet.xml in section <WebFeatures>. After provisioning a new site from onet.xml  all work fine and my feature is shown as activated, but event receivers doesn't fire. It fires only after reactivating my feature (deactivate, then activate it again). But I need my feature works immediately after site provisioning without deactivating and activating it again. Who knows how to solve this problem?

part of ONET.xml



        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5"/>

        <!-- TeamCollab Feature -->

        <Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4"/>

        <!-- MobilityRedirect -->

        <!--My EventReceivers Feature-->

        <Feature ID ="41178843-A6A4-47c7-9EF9-B8A432E02B88"></Feature>





Running a feature activated code during new site provisioning.

I would like to be able to run some simple code that have in a feature whenever a new site is provisioned.  I created the feature and it works just like I want it to.  I left it activated and saved the site template.  Now when I create a new site based on the saved site template the feature activated code no longer runs unless I deactivate and then activate.  I know this isn't suppose to work this way, and after much searching on the internet I am finding the feature stapling (not what I want, that seems to be what I have already done) and SPWebProvisionProvider.  The provider might be what I want but I am not sure how it works and there are no good examples on how to get one created in code and where to place it so that a user can utilize it when creating a new site.  Can someone explain this concept to me in ad nauseum detail.  Thanks in advance.

Weird error when creating a site from a feature receiver


Hello everybody

I'm writing a feature in a sandboxed solution (scope of the feature : Web)

I've added to that feature a feature receiver that is supposed to create a subsite in the site in which it has been activated.

Here is the code

public override void FeatureActivated(SPFeatureReceiverProperties properties)
      string url="";
      using (SPWeb site = properties.Feature.Parent as SPWeb)
          site.Title = "root";
          SPWebTemplateCollection webTemplates = site.Site.RootWeb.GetAvailableWebTemplates(site.Language);
          url = site.IsRootWeb ? "subnews" : site.ServerRelativeUrl.Substring(1) + "/subnews";
          SPWebTemplate webTemplate = (from SPWebTemplate t
                         in webTemplates

feature stapling done against site definition breaks when saving site as a template?

Hi, we have a bunch of feature stapling done against some of our site definitions on a solution we are working on. This feature staple has a bunch of feature dependancies which all work in a variety of ways. One of these dependancies then uses a feature receiver class to do some post provisioning setting up of web part connections and the like. This all works very well when creating a new site from a site definition etc etc. The problem arises when a user opts to provision a site in this way, and then uses the 'save as template' function within sharepoint. (BTW this is WSS 3.0 / MOSS). The site template saves correctly, but now the feature receiver never runs. I'm assuming this is because the associated feature staple doesnt run either? I've looked around and seen some reference to feature stapling not working against templates. Is this true? 

SharePoint how does it know to use a feature default.aspx deployed instead of site definition defaul

I have created a feature which deploys a custom default.aspx page. The deployed file goes to the template\features{featureName} directory. How does SharePoint know to use this default.aspx page instead of the one that is located in SiteTemplates{Site Def name} directory?dave

Feature with wsp for creating specific groups on any site creation

hi, i need to create a sharepoint feature for wss 3.0 with .wsp (wsp for easy deployment) which do folowing funtionality: Ability to run some custom code for creating specific custom groups on every site creation. Feature needs to be activated when deployed so when user create new site it creates groups based on our custom code( i have custom code for creating gorups just need to know how to attached it to feature which works on every site creation event) Any workable example is very helpful for me because i am very confuse and already did reasearch on that. i guess feature stapling is not the solution in my case. Thanks in advanced shaheen

Feature association in site definition( for site and subsite)



in Onet.xml

one configuration --Template  --is for Site collection site definition
second configuration --Template --is for subsite  site definition

when subsite is created with second configuration  receiver Feature
should be activated
I have associated feature  as

<!-- BascBrandGroup -->

FeatureSiteTemplateAssociation Id="AE6860A5-B140-47BB-8FF4-D971FB93D682"

Feature Id and template name is verified.
but feature is not getting activated.

Please suggest better approaches or if sample code for site collection
site def and ( site and subsite) def is available ,pls provide the link

Feature Stapling + on creation of a new site stapling is not effecting + means The resource cannot b



i am working on feature stapling. pls find the code below:

http://www.beckybertram.com/oldblog/index.php?p=33&more=1&c=1&tb=1&pb=1  (i had written the code from this site).

after delpoyment of this solution.

problem: while i am creating a site - it is throwing " The resource cannot be found" error.

on log - file not found.

Very 1st site collection is able to apply. but while i am creating newly (after processing , it is thorwing this issue).

pls help me to make this work, i need to complete this by EOD. pls help me.

Deploying .vb code file to site definition


I'm developing using VS2010. 2 projects: sharepoint site definition and a webapplication in visual basic.net. The code file .vb is not deployed with the sharepoint site definition.

Please anyone can help me.


Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventRecei


Hi all, i found the below error in event log. How can i fix this issue.

Event ID: 6875            Source: Windows SharePoint Services 3

Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver in Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.

: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Please help me out in this issue. Thanks in advance.


K2Blackpearl, Sharepoint, .Net

Automating Site Creation and Feature Activation with PowerShell


I am trying to create a blank site and then loop through the available features for that site and activate them. The problem I am facing is the list of features scoped to "web" that are returned in powershell are not the same list of web features that are visible through the site settings in the SharePoint UI or through the SharePoint 2010 Manager UI.

What I get returned from Powershell is:

DisplayName Id

----------- --

WebPageLibrary 00bfea71-c796-4402-9f2f-0eb9a6e71b18

IssuesList 00bfea71-5932-4f9c-ad71-1557e5751100

WorkflowHistoryList 00bfea71-4ea5-48d4-a4ad-305cf7030140

NoCodeWorkflowLibrary 00bfea71-f600-43f6-a895-40c0de7b0117

SurveysList 00bfea71-eb8a-40b1-80c7-506be7590102

GridList 00bfea71-3a1d-41d3-a0ee-651d11570120

GanttTasksList 00bfea71-513d-4ca0-96c2-6a47775c0119

LinksList 00bfea71-2062-426c-90bf-714c59600103

MobilityRedirect f41cc668-37e5-4743-b4a8-74d1db3fd8a4

workflowProcessList 00bfea71-2d77-4a75-9fca-76516689e21a

TasksList 00bfea71-a83e-497e-9ba0-7a5c597d0107

TeamCollab 00bfea71-4ea5-48d4-a4ad-7ea5c011abe5

AnnouncementsList 00bfea71-d1ce-42de-9c63-a44004ce0104

ObaSimpleSolution d250636f-0a26-4019-8425-a5232d592c01

PictureLibrary 00bfea71-52d4-45b3-b544-b1c71b620109

ContactsList 00bfea71-7e6d-4186-9ba8-c047ac750105

Using List templates - saved template has no site definition id or feature id - does not appear in S

I have a Record Centre site in SharePoint Server 2010 and have created a number of record libraries. Due to a reorganisation, I need to split my main record library up into about 20 separate libraries, so decided to use the list template as a means to create the new libraries with the same content types, views and workflows.

Used one of my libraries with no content and did Library Settings - Save document library as template and gave a name. Seemed to save OK to the List template gallery.

When I go to Site Actions - More Options the new template does not appear

Have done a fair bit of searching and I think the problem is that the .stp does not seem to have any site definition id and no means to add one.

Have enabled the SharePoint Server Publishing feature at the site level, as suggested by another post, but still has not resolved the problem.

Would value any ideas or insight. Thanks

Error loading and running event receiver: Object reference not set to an object instance


I'm getting the following error for my client's SharePoint production server.

Error loading and running event receiver myproject.Receivers.ListItem.ContentApprovalEventHandler in ..., Version=, Culture=neutral, PublicKeyToken=.... Additional information is below.  : Object reference not set to an object instance.    


I know there are few posts already out there explaining the problem but I've not got the one matching my situation. The event receiver is working on dev and staging server but not on production. Few points I can mention here:

1. My event receiver is not calling. I have put a log at the very beginning of the receiver and put the whole event receiver code in try/catch block. In catch block I have thrown a custom error. So if my code would be executed then the custom error would be in log file.

2. The same event receiver is working on development and staging server.

3. Production is a farm whereas dev and staging server is standalone.

4. The production farm has two severs one of which is not configured properly.

5. I have tested with code and made sure the event receiver is registered with the list.


Apparently the problem might be permission/configuration related. Does anyone have any idea what might be the cause?


Wicked Code: Three Cures for Common Site Map Ailments


Data-driven site navigation is among the niftiest and most useful features in ASP. NET 2. 0. To get it working, all you do is create an XML site map file (or a SQL site map if you're using the MSDN®Magazine SqlSiteMapProvider), add a SiteMapDataSource, and bind a TreeView or Menu to the SiteMapDataSource.

Jeff Prosise

MSDN Magazine June 2006

Wicked Code: The SQL Site Map Provider You've Been Waiting For


Now that ASP.NET 2.0 is a shipping product, it seems appropriate to revisit an issue that tops the new features wish lists of many developers: a SQL ServerT site map provider.

Jeff Prosise

MSDN Magazine February 2006

Why do the aks master pages not get applied if the feature is not activated on the top site collecti


I installed AKS 2.0 and activated AKS feature. The problem I found was the aks master pages do not get applied if the feature is not activated on the top site collection. why is so?

example: If i activate the feature on http://<servername>/sites/<sitename> and apply the master page, I dont see any changes.

              But if i activate the same aks feature on http://<servername/ then everything started working on all sites.

              The reason i found is the CSS reference in the aks master pages.

              It reference should be given as follows:

                 for http://<servername>/sites/<sitename> ->  <link rel="stylesheet" type="text/css" href="../../Style%20Library/AKS/Aks_Band_Blueband.css"/>

                 for http://<servername>/ -><link rel="stylesheet" type="text/css" href="/Style%20Library/AKS/Aks_Band_Blueband.css"/>

So my question is, am i missing anything? am i supposed to activate the AKS feature on top level site collection at any cost? if yes, why is so? 

And after applying aks master pages, i see differnece in font sizes. Why the font size is getting changed?


Code to get how many users are logged in to the sharepoint site

How to get the users of my sharepoint who are online.....

Thanx in advance,

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend