Sense/Net SourceCode Field Control

This is a Field Control for Sense/Net ECMS, it provides syntax highlighting.


Binary package

  • Download and unzip the binary package to your Sense/Net bin folder.
  • Move the SyntaxHighlighter folder into the JS folder.
  • in the Web.config file: in the configuration -> system.web -> pages -> controls add the following line:
<add tagPrefix="sn" namespace="SourceCode" assembly="SourceCode" />
  • Now you can add to your Browse ContentView file the SourceCode Control:
<sn:SourceCode ID="MyCode" runat="server" Language="CSharp" FieldName="MyCode" />

As you can see, you can select the language to highlight with Language attribute. Clck here to see all available languages: Available Languages


The field control was made to be able to use any syntax highlighter engine. By default there are 2 engines to select from:
  1. ColorCode - Syntax Highlighting/Colorization for .NET
  2. SyntaxHighlighter - a javascript driven highlighter

You have 2 different options to switch between the engines:
  • You can set a global configuration to for all SourceCode Field Controls:
add to the configuration -> appSettings section in your Web.config file the following line:
<!-- SourceCode Field Control Configuration -->
<add key="Highlighter" value="SourceCode.ColorCodeHighlighter" />
  • Or you can set for only one Filed Control by setting the Highlighter attribute:
<sn:SourceCode ID="MyCode" runat="server" Highlighter="SourceCode.SyntaxHighlighter" Language="CSharp" FieldName="MyCode" />

The highlighter is actually the FullName of the class witch will be instanced to format our text.
And now we are getting to the point: If you don't like the highlighter engines included in the FieldControl, you can simply add your own!

Let's see how can be this done:
  1. Create a new class library
  2. Add reference to SourceCode.dll assembly
  3. implement SourceCode.IHighlighter interface
  4. override the Highlight function:
    1. this function recieves a string, and returns it highlighted
  5. Build your application to the sensenet bin folder

And it's done! So simple :) Now you can add your hightligter class with the following format:
This part is importent! If you miss the namespace or the assembly it won't work!
Let's see the example below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SourceCode;

namespace MyHighlighterNameSpace
    public class MyHighlighter : IHighlighter
        #region IHighlighter Members

        public string Highlight(string textToHightlight, string Language, Page page)


If your assembly called MyHighlighter.dll, than you have to add the following Highlighter attribute:

Have a good time! :)

Last edited Oct 27, 2009 at 5:15 PM by szelpe, version 11