Skenari Biznes:
Ndërmarrjeve të gjerë zbatimi i MOSS për kompaninë prodhuese me 30+ faqet dhe një duzinë disa departamenteve të korporatave.
Objektivi Biznes:
Pavarësisht nga një numër të grupeve të biznesit (departamentet, Lokacionet, etj), të dhëna të caktuara duhet të mbahet në një nivel global. Për shembull, një listë autoritativ mjeshtër i të gjitha lokacionet fizike të kompanisë (e.g. Objektet e prodhimit, 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. Pastaj, 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.
Zgjidhja teknike:
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:
- Define a class which inherits from SPField (one may inherit from other fields if required).
Here is the code for that:
publik klasë XYZZYCorporateLocationField : SPFieldText
{
publik XYZZYCorporateLocationField
(SPFieldCollection Fushat, varg typeName, varg displayName)
: base(Fushat, typeName, displayName) { }
publik XYZZYCorporateLocationField
(SPFieldCollection Fushat, varg displayName)
: base(Fushat, displayName) { }
publik shkel BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl control = i ri XYZZYCorporateLocationFieldControl();
control.FieldName = kjo.InternalName;
kthehem control;
} //get
} // fieldrenderingcontrol
publik shkel varg GetValidatedString(object vlerë)
{
nëse (kjo.Required || value.ToString().Është e barabartë me(String.Empty))
{
hedh i ri SPFieldValidationException ("Department is not assigned.");
}
kthehem base.GetValidatedString(vlerë);
} // getvalidatedstring
} // XYZZYCorporateLocation
- Define another class that inherits from the base field control, si në:
publik klasë XYZZYCorporateLocationFieldControl : BaseFieldControl
{
mbrojtur DropDownList XYZZYCorporateLocationSelector;
mbrojtur shkel varg DefaultTemplateName
{
get
{
kthehem "XYZZYCorporateLocationFieldControl";
}
} // DefaultTemplateName
publik shkel object Vlerë
{
get
{
EnsureChildControls();
kthehem kjo.XYZZYCorporateLocationSelector.SelectedValue;
} // get
i vendosur
{
EnsureChildControls();
kjo.XYZZYCorporateLocationSelector.SelectedValue = (varg)kjo.ItemFieldValue;
} // i vendosur
} // override object Value
mbrojtur shkel pavlefshme CreateChildControls()
{
nëse (kjo.Field == zero || kjo.ControlMode == SPControlMode.Display)
kthehem;
base.CreateChildControls();
kjo.XYZZYCorporateLocationSelector =
(DropDownList)TemplateContainer.FindControl("XYZZYCorporateLocationSelector");
nëse (kjo.XYZZYCorporateLocationSelector == zero)
hedh i ri Exception("ERROR: Cannot load .ASCX file!");
nëse (!kjo.Page.IsPostBack)
{
përdorim (SPSite site = i ri SPSite("http://localhost/enterprisedata"))
{
përdorim (SPWeb web = site.OpenWeb())
{
SPList currentList = web.Lists["Corporate Locations"];
foreach (Pështyj XYZZYCorporateLocation në currentList.Items)
{
nëse (XYZZYCorporateLocation["Title"] == zero) vazhdoj;
varg theTitle;
theTitle = XYZZYCorporateLocation["Title"].ToString();
kjo.XYZZYCorporateLocationSelector.Items.Add
(i ri 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, sigurisht).
-
Implement a control template (.ascx) siç tregohet:
<%@ Control Language="C#" Inherits="Microsoft.SharePoint.Portal.ServerAdmin.CreateSiteCollectionPanel1,Microsoft.SharePoint.Portal,Version=12.0.0.0,Culture=neutral,PublicKeyToken = 71e9bce111e9429c" compilationMode="Always" %>
<%@ Regjistrohem Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version = 12.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c" %> <%@ Regjistrohem Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version = 12.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c" %>
<SharePoint:RenderingTemplate ID="XYZZYCorporateLocationFieldControl" runat="server">
<Shabllon>
<nëpërkë:DropDownList ID="XYZZYCorporateLocationSelector" runat="server" />
</Shabllon>
</SharePoint:RenderingTemplate>
The above is saved into c:\program files\common files\microsoft shared\web server extensions\12\controltemplates.
- Më në fund, 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 version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Emër="TypeName">CorporateLocations</Field>
<Field Emër="ParentType">Tekst</Field>
<Field Emër="TypeDisplayName">Corporate Locations</Field>
<Field Emër="TypeShortDescription">All XYZZY Corporate locations including manufacturing or other facilities.</Field>
<Field Emër="UserCreatable">TRUE</Field>
<Field Emër="ShowInListCreate">TRUE</Field>
<Field Emër="ShowInDocumentLibraryCreate">TRUE</Field>
<Field Emër="ShowInSurveyCreate">TRUE</Field>
<Field Emër="ShowInColumnTemplateCreate">TRUE</Field>
<Field Emër="FieldTypeClass">Conchango.XYZZYCorporateLocationField, XYZZYCorporateLocationField, Version = 1.0.0.0, Culture = neutral, PublicKeyToken=b0b19e85410990c4</Field>
<RenderPattern Emër="DisplayPattern">
<Switch>
<Expr>
<Column />
</Expr>
<Case Vlerë=""/>
<Default>
<HTML>
<![CDATA[<span style="color:Red"><b>]]>
</HTML>
<Column SubColumnNumber="0" HTMLEncode="TRUE"/>
<HTML><![CDATA[</b></hapësirë>]]></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.