MOSS: Eżempju funzjonali - Custom Data Tip

Xenarju Business:

Implimentazzjoni intrapriża wiesgħa ta 'MOSS għall-kumpanija tal-manifattura ma 30+ siti u ta 'dipartimenti ftit għexieren korporattiva.

Għan Business:

Minkejja numru kbir ta 'gruppi ta' negozju (dipartimenti, postijiet, eċċ), ċerta data għandha tinżamm fil-livell globali. Per eżempju, lista kaptan awtorevoli tal-postijiet kollha fiżiċi tal-kumpanija (e.g. faċilitajiet ta 'manifattura, 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. Imbagħad, 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.

Soluzzjoni teknika:

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:

pubbliku klassi XYZZYCorporateLocationField : SPFieldText
{
pubbliku XYZZYCorporateLocationField
(SPFieldCollection oqsma, string typeName, string displayName)
: base(oqsma, typeName, displayName) { }

pubbliku XYZZYCorporateLocationField
(SPFieldCollection oqsma, string displayName)
: base(oqsma, displayName) { }

pubbliku override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl control = ġdid XYZZYCorporateLocationFieldControl();
control.FieldName = dan.InternalName;
ritorn control;
} //get
} // fieldrenderingcontrol

pubbliku override string GetValidatedString(object valur)
{
jekk (dan.Required || value.ToString().Ugwali(String.Empty))
{
tarmi ġdid SPFieldValidationException ("Department is not assigned.");
}
ritorn base.GetValidatedString(valur);
} // getvalidatedstring

} // XYZZYCorporateLocation

  1. Define another class that inherits from the base field control, kif fil-:

pubbliku klassi XYZZYCorporateLocationFieldControl : BaseFieldControl
{
protetti DropDownList XYZZYCorporateLocationSelector;

protetti override string DefaultTemplateName
{
get
{
ritorn "XYZZYCorporateLocationFieldControl";
}
} // DefaultTemplateName

pubbliku override object Valur
{
get
{
EnsureChildControls();
ritorn dan.XYZZYCorporateLocationSelector.SelectedValue;
} // get
stabbiliti
{
EnsureChildControls();
dan.XYZZYCorporateLocationSelector.SelectedValue = (string)dan.ItemFieldValue;
} // stabbiliti
} // override object Value

protetti override null CreateChildControls()
{

jekk (dan.Field == null || dan.ControlMode == SPControlMode.Display)
ritorn;

base.CreateChildControls();

dan.XYZZYCorporateLocationSelector =
(DropDownList)TemplateContainer.FindControl("XYZZYCorporateLocationSelector");

jekk (dan.XYZZYCorporateLocationSelector == null)
tarmi ġdid Eċċezzjoni("ERROR: Cannot load .ASCX file!");

jekk (!dan.Page.IsPostBack)
{

użu (SPSite site = ġdid SPSite("http://localhost/enterprisedata"))
{
użu (SPWeb web = site.OpenWeb())
{

SPList currentList = web.Lists["Corporate Locations"];

foreach (Bżiq XYZZYCorporateLocation fil currentList.Items)
{
jekk (XYZZYCorporateLocation["Title"] == null) continue;

string theTitle;
theTitle = XYZZYCorporateLocation["Title"].ToString();

dan.XYZZYCorporateLocationSelector.Items.Add
(ġdid ListItem(theTitle, theTitle));

} // foreach

} // 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, tal-kors).

  1. Implement a control template (.ascx) kif muri:

<%@ Control Language="C#" Inherits="Microsoft.SharePoint.Portal.ServerAdmin.CreateSiteCollectionPanel1,Microsoft.SharePoint.Portal,Version=12.0.0.0,Culture=neutral,PublicKeyToken = 71e9bce111e9429c" compilationMode="Always" %>
<%
@ Reġistru Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Verżjoni = 12.0.0.0, Kultura = newtrali, PublicKeyToken = 71e9bce111e9429c" %> <%@ Reġistru Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Verżjoni = 12.0.0.0, Kultura = newtrali, PublicKeyToken = 71e9bce111e9429c" %>
<SharePoint:RenderingTemplate ID="XYZZYCorporateLocationFieldControl" runat="server">
<Template>
<asp:DropDownList ID="XYZZYCorporateLocationSelector" runat="server" />
</Template>
</
SharePoint:RenderingTemplate>

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

  1. Fl-aħħarnett, 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:

<?xml Verżjoni="1.0" encoding="UTF-8" ?>
<
FieldTypes>
<
FieldType>
<
Field Isem="TypeName">CorporateLocations</Field>
<
Field Isem="ParentType">Test</Field>
<
Field Isem="TypeDisplayName">Corporate Locations</Field>
<
Field Isem="TypeShortDescription">All XYZZY Corporate locations including manufacturing or other facilities.</Field>
<
Field Isem="UserCreatable">TRUE</Field>
<
Field Isem="ShowInListCreate">TRUE</Field>
<
Field Isem="ShowInDocumentLibraryCreate">TRUE</Field>
<
Field Isem="ShowInSurveyCreate">TRUE</Field>
<
Field Isem="ShowInColumnTemplateCreate">TRUE</Field>
<
Field Isem="FieldTypeClass">Conchango.XYZZYCorporateLocationField, XYZZYCorporateLocationField, Verżjoni = 1.0.0.0, Kultura = newtrali, PublicKeyToken=b0b19e85410990c4</Field>
<
RenderPattern Isem="DisplayPattern">
<
Switch>
<
Expr>
<
Kolonna />
</
Expr>

<Case Valur=""/>

<Default>
<
HTML>
<![CDATA[
<span style="color:Red"><b>]]>
</
HTML>

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

<HTML><![CDATA[</b></medda>]]></HTML>

</
Default>
</
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 ħsibijiet dwar "MOSS: Eżempju funzjonali - Custom Data Tip

  1. Alejandro
    Hi Paul,
    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, per eżempju, doesn’t help me very much :-S).
    Grazzi
  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.

Ħalli Irrispondi

Your email address mhux se jkun ippubblikat. Meħtieġa oqsma huma mmarkati *