.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 a feature activated code during new site provisioning.

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :SharePoint
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.

View Complete Post

More Related Resource Links

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

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

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?


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>





Anonymous Access in site template or feature activated by the site template, is it possible?



I'm building a custom site template and my question is if it's possible to set the anonymous access level in the deployment action.

I tried to create an EventReceiver (FeatureActivated), but I doesn't change the anonymous access level at deploy time. If I deactivate and reativate the feature from the site it works, but I miss the point, because like this it's the same thing then going to Site Permission and change the permission from there.

I do not want to set Anonymous Access from the Site Administration every time.


SharePoint Server Publishing feature--Can't activate on site (activated fine at site collection lev

I have five site collections and one of them seems to have an issue with the SharePoint server publishing feature, which is activated at the site collection level. On any of the sites underneath that site collection, the Server Publishing feature is not activated and throws this error when I try to activate:


One or more field types are not installed properly. Go to the list settings page to delete these fields.

 Troubleshoot issues with Microsoft SharePoint Foundation.

Correlation ID: f1915aff-39e6-4e99-ba2f-34faf71f3102

If I try to create an Enterprise Wiki, I get the same thing:

One or more field types are not installed properly. Go to the list settings page to delete these fields.

I won't be able to create the wiki until I can get the SharePoint Server Publishing feature activated.

Any one have any ideas? the other 4 site collections are fine.

Wicked Code: Running ASMX Web Services on STA Threads


Jeff Prosise describes performance problems in an ASMX Web service that relied on legacy COM and Visual Basic 6.0 to perform key processing tasks and the approach he took to find a fix.

Jeff Prosise

MSDN Magazine October 2006

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

High Availability: Keep Your Code Running with the Reliability Features of the .NET Framework


Reliability requires the capacity to execute a sequence of operations in a deterministic way, even under exceptional conditions. This allows you to ensure that resources are not leaked and that you can maintain state consistency without relying on application domain unloading (or worse, process restarts) to fix any corrupted state. Unfortunately, in the.NET Framework, not all exceptions are deterministic and synchronous, which makes it difficult to write code that is always deterministic in its ability to execute a predetermined sequence of operations. In this article Stephen Toub will show you why, and explore features of the .NET Framework 2.0 that help you to mitigate these situations and write more reliable code.

Stephen Toub

MSDN Magazine October 2005

.NET Internals: Examine Running Processes Using Both Managed and Unmanaged Code


There are plenty of times when you need to get information on running processes, not the least of which is during performance tuning. Using the techniques in this article and special .NET classes you'll see how to get a process' ID, name, priority, number of threads, kernel handle, and memory consumption, as well as its user-mode, kernel-mode, and total elapsed running time and put them to use in a custom app called AssemblyBrowser.

Christophe Nasarre

MSDN Magazine October 2004

Code Name Indigo: A Guide to Developing and Running Connected Systems with Indigo


This article describes a collection of new programming frameworks that are part of "Longhorn," the upcoming version of Windows. "Indigo," the code name for this framework, provides rich support for service-oriented design that is complementary to traditional object-oriented approaches. Indigo marries the best features of .NET Remoting, ASMX, and .NET Enterprise Services into a unified programming and administration model. Indigo's deep support for standard protocols, including HTTP, XML, and SOAP, makes it easier to integrate applications and services without sacrificing security or reliability.

Don Box

MSDN Magazine January 2004

Provisioning: Use Web Services Provisioning to Control Access, Usage, and Billing on Your Site


Building Web Services to provide enterprise-level solutions is only the first step. You need to take care of the infrastructure aspects of your solution as well, including provisioning, billing, security, and reporting. In this article, the author uses the .NET Framework and SQL Server 2000 to design a provisioning system that will take care of all these housekeeping tasks. He discusses the general requirements of a Web Service provisioning system, walks through the implementation, and then outlines various scenarios for putting this system to work.

Chandu Thota

MSDN Magazine December 2002

Is your code running in a SharePoint Sandbox?


You could execute a function call that is not allowed in the sandbox (for example call a static method on SPSecurity) and catch the exception. A better approach is to test the friendly name of you app domain:

AppDomain.CurrentDomain.FriendlyName returns "Sandboxed Code Execution Partially Trusted Asp.net AppDomain"

Because you can never be sure that this string changes in the future, a safer approach will be:


See http://www.sharepointoverflow.com/questions/2051/how-to-check-if-code-is-running-as-sandboxed-solution for a discussion on this topic.

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,


Detect if code is running inside SQL Server.

Can managed code "detect" if it is running in the normal .Net CLR or the special SQL Server CLR? Is there some environment flag or field we can look at at runtime? Thanks Cap'n  

I am using the following code to check to see if a panel is visible or not before running javascript

Using VB, VS 2010, when I run the following code, I get an error because it executes the code even if I have Panel7 set to invisible.  I am trying to use javascript to see if the panel is visible or not before executing the code.var panelRef7 = document.getElementById('<%= Panel7.ClientID %>'); if (panelRef7) { $find('DragP7').add move(savePanelPosition); }  What am I doing wrong?   Thanks

Is it possible to show on a site whether a service is running?

I am trying to have a marker show whether or not a particular service within the services.msc is running on a remote server(s). I have a service called Yardi Services on a virtual server.  I want to be able to show on a dashboard I am creating for work, whether this service in running or stopped.  For some reason this service will randomly stop though I have a auto restart on error.  It is really confusing and so I want to be able to know when it stops so I can restart it.       I have not been able to find anything online to support this.  I am assuming that I would need to create a web service or use WMI?  I am new to this stuff and could use some help or direction.  
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