SharePoint Raw Text Field Control

4 Jan

Sometimes you simply need to dump out the contents of a text field raw, and not have the SharePoint field controls alter you HTML, strip scripts, etc. 

I’m currently using this to display raw HTML that is being programmatically imported into a list.

This is a very simple example of how to make a field control, however you’ll want to ensure you consider things like caching and security before deploying this.

 

    <span class="kwrd">public</span> <span class="kwrd">class</span> RawTextFieldControl : BaseFieldControl
    {
        <span class="kwrd">public</span> XnaRawTextFieldControl()
        {
            <span class="kwrd">base</span>.DisableInputFieldLabel = <span class="kwrd">true</span>;
            <span class="kwrd">base</span>.ControlMode = SPControlMode.Display;
        }

        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> RenderFieldForDisplay(HtmlTextWriter output)
        {
            output.Write(<span class="kwrd">this</span>.ItemFieldValue);
        }
    }
Tweet about this on TwitterShare on Google+Share on FacebookShare on RedditEmail this to someoneShare on LinkedInShare on StumbleUpon

Leave a Reply

Your email address will not be published. Required fields are marked *