using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Security;
namespace Company.Application.Controls
{
[CLSCompliant(false)]
[Guid("01d5cd28-741b-4229-8d47-24e5a068b5af")]
public class OrganisationDropDownField : SPFieldText
{
public OrganisationDropDownField(SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
{
}
public OrganisationDropDownField(SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName)
{
}
public override BaseFieldControl FieldRenderingControl
{
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
get
{
BaseFieldControl fieldControl = new OrganisationDropDownFieldControl();
fieldControl.FieldName = this.InternalName;
return fieldControl;
}
}
public override string GetValidatedString(object value)
{
if (Required && String.IsNullOrEmpty(value.ToString()))
{
throw new SPFieldValidationException("No Organisation selected");
}
return base.GetValidatedString(value);
}
}
}
<%@ Control Language="C#" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" %>
<SharePoint:RenderingTemplate ID="OrganisationDropDownFieldControl" runat="server">
<Template>
<asp:DropDownList ID="OrganisationSelector" runat="server" />
</Template>
</SharePoint:RenderingTemplate>
using System;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace Company.Application.Controls
{
[CLSCompliant(false)]
[Guid("dfbce0dc-3215-4352-b65f-25a83e8b427b")]
public class OrganisationDropDownFieldControl : BaseFieldControl
{
protected DropDownList OrganisationSelector;
protected override string DefaultTemplateName
{
get
{
return "OrganisationDropDownFieldControl";
}
}
public override object Value
{
get
{
EnsureChildControls();
return OrganisationSelector.SelectedValue;
}
set
{
EnsureChildControls();
OrganisationSelector.SelectedValue = (string)this.ItemFieldValue;
}
}
protected override void CreateChildControls()
{
if (Field == null || ControlMode == SPControlMode.Display)
return;
base.CreateChildControls();
OrganisationSelector = (DropDownList)TemplateContainer.FindControl("OrganisationSelector");
if (OrganisationSelector == null)
{
throw new ApplicationException("Error: Cannot load .ascx file");
}
if (OrganisationSelector.Items.Count == 0)
{
if (SPContext.Current.Site != null)
{
SPList orgList = SPContext.Current.Site.RootWeb.Lists["Organisations List"];
if (orgList == null)
{
throw new ApplicationException("Organisations List not found");
}
OrganisationSelector.Items.Add(String.Empty);
foreach (SPItem org in orgList.Items)
{
if (org["Title"] == null)
{
continue;
}
string orgTitle = org["Title"].ToString();
OrganisationSelector.Items.Add(new ListItem(orgTitle, orgTitle));
}
}
}
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">OrganisationDropDownField</Field>
<Field Name="ParentType">Text</Field>
<Field Name="TypeDisplayName">Organisation</Field>
<Field Name="TypeShortDescription">Organisation</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowInListCreate">TRUE</Field>
<Field Name="ShowInSurveyCreate">TRUE</Field>
<Field Name="ShowInDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowInColumnTemplateCreate">TRUE</Field>
<Field Name="SQLType">ntext</Field>
<Field Name="FieldTypeClass">Company.Application.Controls.OrganisationDropDownField, Company.Application.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7389d5f4596c3c69 </Field>
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr>
<Column/>
</Expr>
<Case Value="">
</Case>
<Default>
</Default>
</Switch>
</RenderPattern>
</FieldType>
</FieldTypes>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="F3A12E2E-31EF-478d-AC2A-E389704F281E">
<Assemblies>
<Assembly Location="Company.Application.Controls.dll" DeploymentTarget="GlobalAssemblyCache">
</Assembly>
</Assemblies>
<TemplateFiles>
<TemplateFile Location="XML\fldtypes_OrganisationField.xml" />
<TemplateFile Location="ControlTemplates\OrganisationFieldControl.ascx" />
</TemplateFiles>
</Solution>
<SafeControl Assembly="Company.Application.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7389d5f4596c3c69", Namespace="Company.Application.Controls" TypeName="*" Safe="True" />
;WSP CAB Generation
.Set DiskDirectoryTemplate=CDROM
.Set CompressionType=MSZIP
.Set UniqueFiles=Off
.Set Cabinet=On
Manifest.xml
%assembly%
.Set DestinationDir="XML"
12\Template\XML\fldtypes_OrganisationField.xml
.Set DestinationDir="ControlTemplates"
12\Template\ControlTemplates\OrganisationFieldControl.ascx
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented:
http://www.codeproject.com/Articles/32877/FCKEditor-SharePoint-Integration-Creating-a-Custom