using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Xml;
namespace MyCurrentUserFieldNS
{ public class MyCurrentUserField : SPFieldUser
{ public MyCurrentUserField(SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
{ this.Presence = true;
}
public override bool AllowMultipleValues
{ get
{ return true;
}
set
{ base.AllowMultipleValues = true;
}
}
//There is an issue with the SPFieldUser,setting the 'AllowMultipleValues' resets the
//Control 'Type'. As a workaround, I override this function and update the field schema
public override void OnAdded(SPAddFieldOptions op)
{ base.OnAdded(op);
XmlDocument doc = new XmlDocument();
doc.LoadXml(this.SchemaXml);
XmlNode element = doc.FirstChild;
XmlAttribute attr = doc.CreateAttribute("Mult"); attr.Value = "TRUE";
element.Attributes.Append(attr);
this.SchemaXml = doc.OuterXml;
base.Update();
}
public MyCurrentUserField(SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName)
{ this.Presence = true;
}
public override Type FieldValueType
{ get
{ return typeof(SPFieldUserValueCollection);
}
}
public override BaseFieldControl FieldRenderingControl
{ get
{ BaseFieldControl fldControl = new UserField();
fldControl.FieldName = InternalName;
return fldControl;
}
}
}
}