I needed to remove the content editor dropdown you sometimes see in the form.
The most efficient way to do this is to add een Content Editor WebPart to the form of your list.
This way you could also add any javascript to your edit form, or other things to your page.

Here is the code:

SPList list = web.Lists[LIST_NAME];
string EditFormURL = list.DefaultEditFormUrl;

web.AllowUnsafeUpdates = true;

SPFile file = web.GetFile(EditFormURL);

if (null != file)
{
      using (SPLimitedWebPartManager mgr = file.GetLimitedWebPartManagerPersonalizationScope.Shared))
{
if (null != mgr)
{
//create new webpart object
ContentEditorWebPart contentEditor = new ContentEditorWebPart();
//Add content to CEWP
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement(“Root”);
xmlElement.InnerText = GetValidationScript().ToString();
contentEditor.Content = xmlElement;contentEditor.Content.InnerText = xmlElement.InnerText;

//Add it to the zone
mgr.AddWebPart(contentEditor, “0”, 0);
web.Update();

}
}
}
}

private StringBuilder GetValidationScript()
{

StringBuilder sbScript = new StringBuilder();
string sJQueryURL = “_layouts/JQuery.js”;//exact path of your js file
sbScript.Append(“<script src='” + sJQueryURL + “‘type=’text/javascript’></script>”);
sbScript.Append(“<script type=’text/javascript’>”);
sbScript.Append(“$(document).ready(function() { “);
sbScript.Append(@” $(‘select[id*=””ContentTypeChoice””]’).parent().parent().hide();”);
sbScript.Append(“}); “);
sbScript.Append(“</script>”);
return sbScript;

}

 

 

 

If you have a webpart or a custom form where you use the SharePoint peoplepicker you have to fetch the values of the control to place them into SharePoint.
This is how you do this.

1

 

2

When I press the save button on my form this code I need to use:

string[] userarray = ppTechnicalManager.CommaSeparatedAccounts.ToString().Split(‘,’);
SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();
for (int i = 0; i < userarray.Length; i++)
usercollection.Add(ConvertLoginAccount(userarray[i]));
item [“Technical Manager”]= usercollection;      
public SPFieldUserValue ConvertLoginAccount(string userid)
{
SPFieldUserValue uservalue;
SPSite site = new SPSite(SPContext.Current.Site.Url);
SPWeb web = site.OpenWeb();
SPUser requireduser = web.EnsureUser(userid);
uservalue = new SPFieldUserValue(web, requireduser.ID, requireduser.LoginName);
return uservalue;
}

And now the values will be saved into your list.

If you wwant to retrieve those values from your listitem again and display this into you control:

SPFieldUser userField = (SPFieldUser)list.Fields.GetField(Fields.TechnicalManager);
SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(item[Fields.TechnicalManager].CheckForNull());
ArrayList entityArrayList = new ArrayList();
PickerEntity entity = new PickerEntity();
if (fieldValue.User != null)
{
SPUser user = fieldValue.User;
entity.Key = user.LoginName.ToString();
}
else
{
SPGroup group = SPContext.Current.Web.Groups[fieldValue.LookupValue];
entity.Key = group.LoginName.ToString();
}
entityArrayList.Add(entity);
ppTechnicalManager.UpdateEntities(entityArrayList);

This checks for groups and users.

Hope this helps