Optionally provide private feedback to help us improve this article...

Thank you for your feedback!


A Hello World Plug-In

In this example we'll create a very basic plug-in to display the text "Hello World" within InstantForum.

First we'll need a user control to hold the mark-up / html / controls for our plug-in...

HelloWorld.ascx (plug-in UI)

Our Hello World user control for this plug-in is very basic and contains a single ASP.NET Label control which we'll populate from the plug-ins code-behind with the words "Hello World".

The "Inherits" attribute on the control directive should contain the fully qualified name to your plug-ins code namespace & class.

<%@ Control Inherits="InstantForum.Plugins.HelloWorld" %> 
<asp:Label ID="lblHelloWorld" runat="server" />

In our code-behind we'll set-up our label control and populate this with the hello world text...

HelloWorld.vb / HellowWorld.cs (Plug-In Code)

This code will be compiled into an assembly called "InstantForum.Plugins.HelloWorld.dll"...

VB.NET

Namespace InstantForum.Plugins

Public Class HelloWorld
Inherits InstantASP.Common.UI.Base.Plugin
Implements InstantASP.Common.Plugins.IPlugin

Public Sub New()

' setup plugin name
Me.Name = "Hello World Sample Plugin"
' optional author information
Me.Author = "InstantASP Ltd"
' the location of our user control from the web applications root
Me.PluginFileName = "~/Plugins/HelloWorld.ascx"

End Sub

' method to setup controls within plugins ascx file
Protected Overrides Sub InitializePlugin(ByVal ctlSkin As System.Web.UI.Control)

' find the label control within our plugins .ascx file
Dim lblHelloWorld As System.Web.UI.WebControls.Label = _
CType(ctlSkin.FindControl("lblHelloWorld"), System.Web.UI.WebControls.Label)

' update the text if we found the control
If Not lblHelloWorld Is Nothing Then
lblHelloWorld.Text = "Hello World!"
End If

End Sub

Public Overloads Sub OnPluginInit(ByVal context As InstantASP.Common.Plugins.IPluginContext) Implements InstantASP.Common.Plugins.IPlugin.OnPluginInit

MyBase.OnPluginInit(context)

End Sub

Public Overloads Sub OnPluginLoad(ByVal context As InstantASP.Common.Plugins.IPluginContext) Implements InstantASP.Common.Plugins.IPlugin.OnPluginLoad

MyBase.OnPluginLoad(context)

End Sub

Public Overloads Sub OnPluginPreRender(ByVal context As InstantASP.Common.Plugins.IPluginContext) Implements InstantASP.Common.Plugins.IPlugin.OnPluginPreRender

MyBase.OnPluginPreRender(context)

End Sub

Public Overloads Sub OnPluginRender(ByVal writer As System.Web.UI.HtmlTextWriter, _
ByVal context As InstantASP.Common.Plugins.IPluginContext) Implements InstantASP.Common.Plugins.IPlugin.OnPluginRender

MyBase.OnPluginRender(writer, context)

End Sub

End Class

End Namespace

C#

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
namespace InstantForum.Plugins
{

public class HelloWorld : InstantASP.Common.UI.Base.Plugin, InstantASP.Common.Plugins.IPlugin
{

public HelloWorld()
{

// setup plugin name
this.Name = "Hello World Sample Plugin";
// optional author information
this.Author = "InstantASP Ltd";
// the location of our user control from the web applications root
this.PluginFileName = "~/Plugins/HelloWorld.ascx";

}

// method to setup controls within plugins ascx file
protected override void InitializePlugin(System.Web.UI.Control ctlSkin)
{

// find the label control within our plugins .ascx file
System.Web.UI.WebControls.Label lblHelloWorld = (System.Web.UI.WebControls.Label)ctlSkin.FindControl("lblHelloWorld");

// update the text if we found the control
if ((lblHelloWorld != null)) {
lblHelloWorld.Text = "Hello World!";
}

}

public void OnPluginInit(InstantASP.Common.Plugins.IPluginContext context)
{

base.OnPluginInit(context);

}

public void OnPluginLoad(InstantASP.Common.Plugins.IPluginContext context)
{

base.OnPluginLoad(context);

}

public void OnPluginPreRender(InstantASP.Common.Plugins.IPluginContext context)
{

base.OnPluginPreRender(context);

}

public void OnPluginRender(System.Web.UI.HtmlTextWriter writer, InstantASP.Common.Plugins.IPluginContext context)
{

base.OnPluginRender(writer, context);

}

}

}

Installing The Plug-in

For this Hello World example we'll need to simply copy the user control into the "Plugins" folder within the root of your InstantForum folder.You can set the location to look for your .ascx file from within your plug-ins code-behind. You'll see in the above example within the constructor for the Hello World class we set a SkinFileName property.  This is used to tell the code where to look for your plug-ins user control.

Your plug-ins don't have to reside within the Plugins folder however we'll be suggesting this to keep things organized.

Copy your plug-ins DLL into the InstantForum \bin directory...

Make InstantForum aware of your plug-in.

Once you've copied your plug-in user control & DLL you'll need to let InstantForum know to use your plug-in. This is very simple and we require is a couple of lines of code within your InstantForum web.config file.

For plug-ins to work you must ensure the following configuration section is present within your InstantForum web.config. This is present by default with InstantForum 2010 and above...

<sectionGroup name="InstantASP.Common">
    <section name="Plugins" type="InstantASP.Common.Plugins.PluginSectionHandler" />
</sectionGroup>

Then add your custom plug-ins section within the web.config as shown below...

<InstantASP.Common>
    <Plugins>
         <Plugin type="InstantForum.Plugins.HelloWorld, InstantForum.Plugins.HelloWorld" />
    </Plugins>
</InstantASP.Common >

The "type" attribute within the Plugin element conains the full path to your plug-ins class and the plug-ins assembly name.

For example...

<Plugin type="YourNameSpace.YourClassName, YourAssemblyName" />

In our example our Hello World Class is located within the InstantForum.Plugins namespace and this is compiled into an assembly with an identical name. So our HelloWorld Plugin element reads..

<Plugin type="InstantForum.Plugins.HelloWorld, InstantForum.Plugins.HelloWorld" />

You can of course add as many plug-ins as you wish here.

Testing the Hello World Plug-In

Now we've registered the hello world plug-in with InstantForum within the web.config file lets take a look at the forum within a browser. You'll see our plug-ins user control has been automatically added to the end of the pages control collection...

Obviously this particular plug-in is not very useful however it demonstrates the basic idea of how to develop & add plug-ins to InstantForum without having to modify the core product code.

This hello world example simply adds our hello world plug-in to the end of the pages control collection. IF you wish to add your plug-ins to specific locations on pages please see our Adding InstantForum Plug-Ins to your Page" article.