In SharePoint 2010, if you add a field to the list or document library, set the field type to "multi-line text" and set the text type to "rtf ", like this:
When you add or edit a list item, you will see the rich text edit box below. Everything looks good. Through this editing interface, you can easily set the font, color, and format of text, insert images, and insert links... wait, where is the button for inserting the link ??
Then, you will find that this rich text editing box does not have a "insert link" button! In rich text, hyperlinks are supported, but the insert hyperlink button is missing, which makes operations abnormal and troublesome.
On the page, the operation used to display the rich text editing box is performed by form in the layouts \ 2052 (or 1033, depending on the language version of SharePoint) folder. javaScript scripts contained in the JS file. In the form. js file, there is a function named rte_converttextareatorichedit, which is used to render the rich text editor that the user sees. Note that fallowhyperlink, the 3rd parameter of this function, can be seen from the parameter name. It is used to control whether the rich text editor allows hyperlinks.
However, on the list form page, when calling the rte_converttextareatorichedit function to render the rich text edit box, 3rd parameters are always input with the false value. In this way, the rich text editing box is displayed, and no button is inserted.
Knowing the cause of the problem is easy to solve. We only need to let the script on the page pass true to the 3rd parameter when calling the rte_converttextareatorichedit function. The following describes how to use template control to solve this problem (you can also use different solutions ).
Create a new. ascx file and give it a file name that is not easily named, for example, richtextfieldwithhyperlink. ascx. The content of the file is as follows:
<%@ Control Language="C#" AutoEventWireup="false" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" %>
<%@ Register TagPrefix="ApplicationPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.ApplicationPages.WebControls" %>
<%@ Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" Src="~/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" Src="~/_controltemplates/ToolBarButton.ascx" %>
<SharePoint:RenderingTemplate ID="RichTextField" runat="server">
<Template>
<span dir="<%$Resources:wss,multipages_direction_dir_value%>" runat="server">
<asp:TextBox id="TextField" TextMode="MultiLine" runat="server"/>
<input id="TextField_spSave" type="HIDDEN" name="TextField_spSave" runat="server"/>
</span>
<script type="text/javascript">
if (typeof RTE_ConvertTextAreaToRichEdit !== "undefined") {
if (typeof RTE_ConvertTextAreaToRichEdit.hooked === "undefined") {
var RTE_ConvertTextAreaToRichEdit2 = RTE_ConvertTextAreaToRichEdit;
var RTE_ConvertTextAreaToRichEdit = function (
strBaseElementID,
fRestrictedMode,
fAllowHyperlink,
strDirection,
strWebLocale,
fSimpleTextOnly,
fEditable,
fUseDynamicHeightSizing,
iMaxHeightSize,
iMinHeightSize,
strMode,
urlWebRoot,
strThemeUrl,
strBodyClassName,
fAllowRelativeLinks,
strBaseUrl,
fUseDynamicWidthSizing,
iMaxWidthSize,
iMinWidthSize,
fEnforceAccessibilityMode,
fPreserveScript,
fHookUpEvents,
fGenerateToolbar
) {
RTE_ConvertTextAreaToRichEdit2(
strBaseElementID,
fRestrictedMode,
true,
strDirection,
strWebLocale,
fSimpleTextOnly,
fEditable,
fUseDynamicHeightSizing,
iMaxHeightSize,
iMinHeightSize,
strMode,
urlWebRoot,
strThemeUrl,
strBodyClassName,
fAllowRelativeLinks,
strBaseUrl,
fUseDynamicWidthSizing,
iMaxWidthSize,
iMinWidthSize,
fEnforceAccessibilityMode,
fPreserveScript,
fHookUpEvents,
fGenerateToolbar
);
};
RTE_ConvertTextAreaToRichEdit.hooked = true;
}
}
</script>
</Template>
</SharePoint:RenderingTemplate>
Copy the file to the "Program Files \ common files \ microsoft shared \ Web Server Extensions \ 14 \ template \ controltemplates" folder.
Execute iisreset on the server to see the effect. The "insert link" button appears on the toolbar.
Note: Do not manually place the. ascx file in the controltemplates folder. In your SharePoint project, you should map the. ascx file to the controltemplates folder on the server.