Custom Field Type -> User : <Field Name="ParentType">User</Field>
If you will create a Custom Field Type user types the parent, then one proceeds as before, only two places would have to change something.
<%@ Page Language="C#" Inherits="[my namespace].[my class], [assembly-name], Version=1.0.0.0, Culture=neutral, PublicKeyToken=[Token ID]" MasterPageFile="~/_layouts/dialog.master" %> first . Fldtypes_ [your name] xml \u0026lt;Field Name="ParentType"> User \u0026lt;/ Field>
second field control required on the overridden method get value a certain size [Sharepoint UserId] # [Sharepoint user name] as a string.
get
{return 1; # My Name ";}
} Sharepoint UserId and UserName is obtained as follows:
Current User:
SPSite = oSiteCollection SPContext.Current.Site;
using (SPWeb = oWebsite oSiteCollection.RootWeb) { SPUser oUser = oWebsite.CurrentUser;
oUser.Name / / The Sharepoint username
oUser.ID; / / The Sharepoint UserId
}
A user from a group:
using (SPSite SPSite = new SPSite ("[URL to my Sharepoint instance]"))
{
using (SPWeb SPWeb = spSite.RootWeb) {
foreach (. SPUser spWeb.SiteGroups user in ["[My group name]"] users) {
user.Name;
user.ID;}
}}
third Field class inherits from its normal Custom Field Types of the base class SPField. In this case, it must be SPFieldUser. The rest of the code remains the same. If you want to set a default value, you can override the corresponding property.
public class [your name] Field: SPFieldUser
{...
NOTE: If you use SPField as a base class, then the value remains empty in the list.
If you want to create a custom-field-type of parent-type user, then you just create your custom-field-type like any other and make changes at two spots.
first fldtypes_ [your name] xml
There you have to define the following parent type.
\u0026lt;Field Name="ParentType"> User \u0026lt;/ Field>
2. FieldControl requires a special format in the get function of the overridden method Value. [Sharepoint UserId];#[Sharepoint UserName] as string.
public override object Value
{
get {
return "1;#My name"; }
}
You can get the values of Sharepoint UserId or UserName like this:
Current user:
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.RootWeb) { SPUser oUser = oWebsite.CurrentUser;
oUser.Name; //The Sharepoint UserName
oUser.ID; //The Sharepoint UserId
}
User from a specified group:
using (SPSite spSite = new SPSite("[URL of my Sharepoint-instance]"))
{
using (SPWeb spWeb = spSite.RootWeb) {
foreach (SPUser user in spWeb.SiteGroups["[My group-name]"].Users)
{
user.Name; //The Sharepoint UserName
user.ID; //The Sharepoint UserId }
}
}
3. Usual custom-field-types inherit from the base-class SPField. In this case your class needs to inherit from SPFieldUser. The rest of the code remains the same. If you want to set a default-value, then you need to override the property DefaultValue.
public class [Your name]Field : SPFieldUser
{ ...
HINT: If you do use SPField as the base class, then the value in the list will remain empty.
0 comments:
Post a Comment