Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint Webpart Properties / Rich text box?

Is it possible to make a String in a web part properties editable with a rich text box (to be able to use the Bold, etc.) ?

UPDATE / SOLUTION

The 1st class is the "Custom property" that should appear in the toolbar

   using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.SharePoint;    
    namespace MyCustomProperty
    {
        public class RichTextToolbarProperty : Microsoft.SharePoint.WebPartPages.ToolPart
        {

            InputFormTextBox textBox;
            Panel toolPartPanel;

            protected override void CreateChildControls()
            {
                toolPartPanel = new Panel();
                toolPartPanel.GroupingText = "Default text here";
                textBox = new InputFormTextBox();
                textBox.TextMode = TextBoxMode.MultiLine;
                textBox.Rows = 10;
                textBox.RichText = true;
                textBox.RichTextMode = SPRichTextMode.FullHtml;

                BasePublicationWebPart wp = (BasePublicationWebPart)this.ParentToolPane.SelectedWebPart;
                textBox.Text = wp.DefaultText;

                toolPartPanel.Controls.Add(textBox);
                Controls.Add(toolPartPanel);
                base.CreateChildControls();
            }

            public override void ApplyChanges()
            {
                BasePublicationWebPart wp = (BasePublicationWebPart)this.ParentToolPane.SelectedWebPart;
                wp.DefaultText = textBox.Text;
            }

        }
    }

The 2nd class is the WebPart :

using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

using System.ComponentModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

namespace MyWebPart
{

    public abstract class BasePublicationWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{

        public string DefaultText
        {
            get
            {
                return _defaultText;
            }
            set { _defaultText = value; }
        }

        public override ToolPart[] GetToolParts()
        {

            ToolPart[] allToolParts = new ToolPart[3];
            WebPartToolPart standardToolParts = new WebPartToolPart();
            CustomPropertyToolPart customToolParts = new CustomPropertyToolPart(); 

            allToolParts[0] = standardToolParts;
            allToolParts[1] = customToolParts;
            allToolParts[2] = new MyCustomProperty.RichTextToolbarProperty(); 

            return allToolParts;
        }
// ... some usual web part code should go here ... ///
like image 373
tinky05 Avatar asked Nov 14 '22 13:11

tinky05


1 Answers

Yes it is, you might want to inspect, how the "Custom Content Editor Web Part" is built: http://www.codeproject.com/KB/sharepoint/Custom_CEWP_4_SharePoint.aspx

like image 77
naivists Avatar answered Jan 10 '23 12:01

naivists