XsnFeatureReceiver class
Based on the SPFeatureReceiver class and used to trap the activation, deactivation, installation, or uninstallation of a SharePoint feature containing an InfoPath form template.
Microsoft.SharePoint.SPFeatureReceiver
Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver
Assembly: Microsoft.Office.InfoPath.Server (in Microsoft.Office.InfoPath.Server.dll)
Use the XsnFeatureReceiver class to trap events that are raised after an InfoPath form template installation, uninstallation, activation, or deactivation on the server. The assembly and class name used to trap these events must be referenced in the feature.xml file used to deploy the SharePoint feature containing one or more InfoPath form templates.
Note
|
|---|
It is not possible to cancel installation or uninstallation through feature events. |
Using the XsnFeatureReceiver Class
You can use the XsnFeatureReceiver class by directly referencing the class in your feature definition. For example, a form template named Example.xsn is located in a custom feature folder along with the Feature.xml and Elements.xml file. The custom feature folder is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES. The feature is deployed using the command line "stsadm -o installfeature -filename FeatureFolderName\feature.xml". The feature is then activated to a SharePoint site with the command line "stsadm -o activatefeature –filename FeatureFolderName\Feature.xml -url http://ServerName/".
Important
|
|---|
The FeatureFolderName, ServerName, Feature Id, and File Name are placeholder values. Substitute values that pertain to your environment. |
Feature.xml
<?xml version="1.0" encoding="us-ascii" standalone="yes"?>
<Feature Id="2CCB7482-69D4-4084-AEC2-A867C91FEF88"
Title="Simple Form Template"
Description="This is simple form template"
Version="1.0.0.0"
Scope="Site"
ReceiverClass="Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver"
ReceiverAssembly="Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml" />
<ElementFile Location="Example.xsn" />
</ElementManifests>
<ActivationDependencies>
<ActivationDependency FeatureId="C88C4FF1-DBF5-4649-AD9F-C6C426EBCBF5" />
</ActivationDependencies>
</Feature>
Elements.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="XSN" Url="FormServerTemplates" RootWebOnly="TRUE">
<File Url="Example.xsn" Name="Example.xsn" Type="GhostableInLibrary" />
</Module>
</Elements>
Extending the XsnFeatureReceiver Class
If you wish to extend the XsnFeatureReceiver class using code similar to the example below, the following example Feature.xml and Elements.xml files are required to deploy the feature with the command line "stsadm -o installfeature -filename FeatureFolderName\feature.xml". The feature is then activated to a SharePoint site with the command line "stsadm -o activatefeature –filename FeatureFolderName\Feature.xml -url http://ServerName/Sitecollection".
Important
|
|---|
The FeatureFolderName, ServerName, Sitecollection, Feature Id, ReceiverAssembly, ReceiverClass, and File Name are placeholder values. Substitute the values that pertain to your environment and custom XsnFeatureReceiver class. |
Feature.xml
<?xml version="1.0"?>
<Feature Id="E57DD3BD-C295-4f9d-A2F1-BB791257CCDC" Title="My Custom Page"
Description="This feature adds an aspx page with a hosted
XmlFormView control" Version="1.0.0.0" Scope="Web"
ReceiverAssembly="Freceive, Version=1.0.0.0, Culture=neutral, PublicKeyToken=50b6d1f1666192d2"
ReceiverClass="Freceive.ReceivedXSN"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml"/>
</ElementManifests>
</Feature>
Elements.xml
<?xml version="1.0"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module>
<File Name="MyCustomPage.aspx" Type="GhostableInLibrary"/>
</Module>
</Elements>
In the following example, a Windows class library is used to receive SharePoint feature events. The assembly must be signed and deployed to the Global Assembly Cache (GAC), much like other custom SharePoint assemblies.
[C#]
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.InfoPath.Server.Administration;
namespace Freceive
{
public class ReceivedXSN : XsnFeatureReceiver
{
public override void FeatureActivated(Microsoft.SharePoint.SPFeatureReceiverProperties properties)
{
FeatureActivated(properties);
SPFeatureDefinition xsnDefinition = properties.Feature.Definition;
Guid xsnID = properties.Feature.DefinitionId;
Console.WriteLine("Freceive: Feature Definition is " + xsnDefinition);
Console.WriteLine("Freceive: Feature ID is " + xsnID);
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
public override void FeatureDeactivating(Microsoft.SharePoint.SPFeatureReceiverProperties properties)
{
base.FeatureDeactivating(properties);
Console.WriteLine("Freceive: Deactivated");
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
public override void FeatureInstalled(Microsoft.SharePoint.SPFeatureReceiverProperties properties)
{
Console.WriteLine("Freceive: Installed");
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
public override void FeatureUninstalling(Microsoft.SharePoint.SPFeatureReceiverProperties properties)
{
base.FeatureUninstalling(properties);
Console.WriteLine("Freceive: Uninstalling");
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
Note
Important