Blog Posts

Monday, March 21, 2011

Tweaking Infragistics WebHtmlEditor

One of the requirements in my project was to do some changes to the WebHtmlEditor in ASP.Net page.  I thought it could be useful for others if I shared the code. 


To disable the toolbar buttons of WebHtmlEditor:
Here I am disabling the Open button of toolbar.  We can identify the buttons using the method FindByKeyOrAction() of the control.  Every button on toolbar is identified by the Action Name.  For open page it is "Open".


infraEditor.FindByKeyOrAction("Open").Enabled = false;




Similarly some actions - InsertImage, InsertFlash and InsertWindowsMedia.


Adding fonts to the fonts dropdown:
We can add the fonts to the fonts dropdown in addition to the existing basic fonts. To add 'Times New Roman' to the font names drop down-


ToolbarDropDown ddlFonts = (ToolbarDropDown)infraEditor.FindByKeyOrAction("FontName");
ddlFonts.Items.Add(new ToolbarDropDownItem("Times New Roman","Times New Roman"));

Similarly to add all the windows registered fonts-

ToolbarDropDown ddlFonts = (ToolbarDropDown)infraEditor.FindByKeyOrAction("FontName");
InstalledFontCollection fonts = new InstalledFontCollection();
foreach (FontFamily family in fonts.Families)
{
    ddlFonts.Items.Add(new ToolbarDropDownItem(family.Name,family.Name));
}
Inserting Image:
For inserting images, first we need to set the UploadedFilesDirectory property to tell the control to save the uploaded files by user.  So that we the control can refer these files by a virtual path.



<ighedit:webhtmleditor height="450" id="infraEditor" runat="server" uploadedfilesdirectory=".\UploadedFiles" width="850">
When you run the application and click on the insert image, it will show a dialog box and can upload images and insert through it.


Similarly we can insert the flash and windows media also.


No comments:

Post a Comment