МОСС: Функционална Пример - Цустом Тип података

Пословни сценарио:

Целом предузећу имплементација маховина за производне компаније са 30+ сајтови и неколико одељења корпоративне десетина.

Пословни циљ:

Упркос мноштву пословних група (одељења, Локације, итд), одређени подаци треба да се одржава на глобалном нивоу. На пример, ауторитативан господар списак свих физичких локација предузећа (e.g. производни објекти, warehouse locations, sales offices) should be maintained in a central location.

Technical Problem:

The enterprise taxonomy was implemented using multiple site collections. We would have liked to create the authoritative list of physical locations in a custom WSS list. Онда, when we needed to have a column in a content type (or a column added to a list or doc library) that contained corporate locations, we would create a column using the "lookup" datatype and point to this master list.

Unfortunately, lookup datatypes must access a source list "locally" meaning that our authoritative list cannot span site collections.

Техничко решење:

Implement a new custom data type implemented based on SPField and represented as a DropDownList in the UI whose ListItems populate from the master WSS list.

We created a new site collection called "http://localhost/EnterpriseData". There, we created a custom list named "Corporate Locations". This list just uses the standard "Title" field to contain the list of actual corporate locations.

One follows several discrete steps to create a custom data type in WSS. They are:

  1. Define a class which inherits from SPField (one may inherit from other fields if required).

Here is the code for that:

јавност класа XYZZYCorporateLocationField : SPFieldText
{
јавност XYZZYCorporateLocationField
(SPFieldCollection fields, ниска typeName, ниска displayName)
: base(fields, typeName, displayName) { }

јавност XYZZYCorporateLocationField
(SPFieldCollection fields, ниска displayName)
: base(fields, displayName) { }

јавност заменити BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl control = нови XYZZYCorporateLocationFieldControl();
control.FieldName = ово.InternalName;
повратак control;
} //get
} // fieldrenderingcontrol

јавност заменити ниска GetValidatedString(објекат вредност)
{
ако (ово.Required || value.ToString().Једнако(String.Empty))
{
бацити нови SPFieldValidationException ("Department is not assigned.");
}
повратак base.GetValidatedString(вредност);
} // getvalidatedstring

} // XYZZYCorporateLocation

  1. Define another class that inherits from the base field control, као у:

јавност класа XYZZYCorporateLocationFieldControl : BaseFieldControl
{
заштићен DropDownList XYZZYCorporateLocationSelector;

заштићен заменити ниска DefaultTemplateName
{
get
{
повратак "XYZZYCorporateLocationFieldControl";
}
} // DefaultTemplateName

јавност заменити објекат Вредност
{
get
{
EnsureChildControls();
повратак ово.XYZZYCorporateLocationSelector.SelectedValue;
} // get
сет
{
EnsureChildControls();
ово.XYZZYCorporateLocationSelector.SelectedValue = (ниска)ово.ItemFieldValue;
} // сет
} // override object Value

заштићен заменити воид CreateChildControls()
{

ако (ово.Field == null || ово.ControlMode == SPControlMode.Display)
повратак;

base.CreateChildControls();

ово.XYZZYCorporateLocationSelector =
(DropDownList)TemplateContainer.FindControl("XYZZYCorporateLocationSelector");

ако (ово.XYZZYCorporateLocationSelector == null)
бацити нови Изузетак("ERROR: Cannot load .ASCX file!");

ако (!ово.Page.IsPostBack)
{

коришћење (СПСите site = нови СПСите("http://localhost/enterprisedata"))
{
коришћење (СПВеб web = site.OpenWeb())
{

СПЛист currentList = web.Lists["Corporate Locations"];

фореацх (Пљунути XYZZYCorporateLocation у currentList.Items)
{
ако (XYZZYCorporateLocation["Title"] == null) наставити;

ниска theTitle;
theTitle = XYZZYCorporateLocation["Title"].ТоСтринг();

ово.XYZZYCorporateLocationSelector.Items.Add
(нови ListItem(theTitle, theTitle));

} // фореацх

} // using spweb web = site.openweb()
} // using spsite site = new spsite("http://localhost/enterprisedata")

} // if not a postback

} // CreateChildControls

} // XYZZYCorporateLocationFieldControl

The above code basically implements the logic for populating the DropDownList with values from the WSS custom list located at http://localhost/enterprisedata and named "Corporate Departments".

I defined both classes in a single .cs file, compiled it and put it into the GAC (strong required, наравно).

  1. Implement a control template (.ascx) као што је приказано:

<%@ Control Language="C#" Inherits="Microsoft.SharePoint.Portal.ServerAdmin.CreateSiteCollectionPanel1,Microsoft.SharePoint.Portal,Version=12.0.0.0,Culture=neutral,ПублицКеиТокен = 71е9бце111е9429ц" compilationMode="Always" %>
<%
@ Регистар Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Верзија = 12.0.0.0, Култура = неутрална, ПублицКеиТокен = 71е9бце111е9429ц" %> <%@ Регистар Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Верзија = 12.0.0.0, Култура = неутрална, ПублицКеиТокен = 71е9бце111е9429ц" %>
<СхареПоинт:RenderingTemplate ИД="XYZZYCorporateLocationFieldControl" runat="server">
<Шаблон>
<аспида:DropDownList ИД="XYZZYCorporateLocationSelector" runat="server" />
</Шаблон>
</
СхареПоинт:RenderingTemplate>

The above is saved into c:\program files\common files\microsoft shared\web server extensions\12\controltemplates.

  1. Коначно, we create an XML file to save into the …..\12\XML directory. This is CAML that defines our custom data type and for my example, looks like this:

<?КСМЛ верзија="1.0" кодирање="УТФ-8" ?>
<
FieldTypes>
<
FieldType>
<
Field Име="ТипеНаме">CorporateLocations</Field>
<
Field Име="ParentType">Текст</Field>
<
Field Име="TypeDisplayName">Corporate Locations</Field>
<
Field Име="TypeShortDescription">All XYZZY Corporate locations including manufacturing or other facilities.</Field>
<
Field Име="UserCreatable">TRUE</Field>
<
Field Име="ShowInListCreate">TRUE</Field>
<
Field Име="ShowInDocumentLibraryCreate">TRUE</Field>
<
Field Име="ShowInSurveyCreate">TRUE</Field>
<
Field Име="ShowInColumnTemplateCreate">TRUE</Field>
<
Field Име="FieldTypeClass">Conchango.XYZZYCorporateLocationField, XYZZYCorporateLocationField, Версион = 1.0.0.0, Култура = неутрална, PublicKeyToken=b0b19e85410990c4</Field>
<
RenderPattern Име="DisplayPattern">
<
Switch>
<
Expr>
<
Column />
</
Expr>

<Case Вредност=""/>

<Уобичајено>
<
HTML>
<![ЦДАТА[
<span style="color:Red"><Б>]]>
</
HTML>

<
Column SubColumnNumber="0" HTMLEncode="TRUE"/>

<HTML><![ЦДАТА[</Б></распон>]]></HTML>

</
Уобичајено>
</
Switch>

</
RenderPattern>
</
FieldType>
</
FieldTypes>
This XML file adds the custom data type to the WSS "library" and matches it up against the GAC’d assembly.

After moving all these bits into place, iisreset on the server and it should all start working nicely.

3 мисли о "МОСС: Функционална Пример - Цустом Тип података

  1. Alejandro
    Здраво Павле,
    First of all, thanks for the article, because it’s very interesting. Only one question;
    Do you know if it’s posible to render correctly a custom field type in the datasheet view of a list?
    Because every custom field type I create it’s shown as read-only in datasheet view (and the MSDN, на пример, doesn’t help me very much :-С).
    Хвала
  2. Lyndsay

    I am attempting to implement your solution. However I instead of DropDownList, I only have the option for a DropDownChoiceList. Do you happen to know how to add items to a DropDownChoiceList? We are using SharePoint 2007 SP1 and Visual Studio 2005 SP1.

Леаве а Репли

Ваша емаил адреса неће бити објављена. Обавезна поља су означена *