Application of tagMapping in SharePoint
In the custom development of SharePoint, it involves more or less modifying some default controls or extending and restricting the functions of existing controls, in the past, we basically re-developed controls to replace the original controls. Here we will introduce another implementation method.
First, let's get to know about tagMapping.
Microsoft's definition:
Defines a set of tag types that are remapped to other tag types during compilation.
This element is a new element in. NET Framework 2.0.
<TagMapping>
<Add/>
<Remove/>
<Clear/>
</TagMapping>
From the above brief introduction, we can know that the tagMapping element defines a set of tag types, which are remapped to other tag types during compilation. This re- ing will cause the ing type to replace the original tag type of all pages and controls in the ASP. NET application within the scope of the configuration file.
Therefore, if we modify the original control and configure the custom type in web. config, we can extend the default control.
The following example shows the specific implementation method.
In this example, we expand SharePoint People Picker and add our verification method. We disable users from searching keywords whose usernames contain Eric.
Create an empty SharePoint project, create a new class, and inherit from.
Our verification logic needs to be placed in ValidateEntity, so we need to rewrite the ValidateEntity method. In this method, you can place any logic you need. The simple code is as follows.
Public override Microsoft. SharePoint. WebControls. PickerEntity ValidateEntity (Microsoft. SharePoint. WebControls. PickerEntity entity)
{
Microsoft. SharePoint. WebControls. PickerEntity vEntity = entity;
If (vEntity. DisplayText. Contains ("Eric "))
{
VEntity. IsResolved = false;
}
Return base. ValidateEntity (entity );
}
Of course, you can also overload other methods, such as CreateChildControls and add your own controls.
Compile, package, and add tagmapping In the last step after deployment.
Open the web under the SharePoint application directory. config (which web application requires this verification logic, you need to add tagMapping to the corresponding web. config, you can also use Feature to automatically add tagMapping ).
<TagMapping>
<Add tagType = "System. web. UI. webControls. sqlDataSource, System. web, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "mappedTagType =" Microsoft. sharePoint. webControls. SPSqlDataSource, Microsoft. sharePoint, Version = 14.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c "/>
<Add tagType = "Microsoft. sharePoint. webControls. peopleEditor, Microsoft. sharePoint, Version = 14.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c "mappedTagType =" SP2010.WebControls. peopleEditor, MWLINK. webControls, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = c7d5eba68c789280 "/>
</TagMapping>
Open the SharePoint site and try to search for Eric users using the People Picker control. Then, an error will be reported that the user cannot be found.