Friday, August 5, 2011

Save values from peopleEditor control to Sharepoint List


Microsoft.SharePoint.WebControls.PeopleEditor
<SharePoint:PeopleEditor ID="myPeoplePicker" runat="server" Width="300" BorderStyle="Solid" BorderColor="Black"BorderWidth="1" />


            SPSite site = SPContext.Current.Site;
            SPListItem items = null;
            using (SPWeb web = Site.OpenWeb())
            {
                SPList list = web.Lists["Users"];
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    items = list.Items.Add();
                });
                items["FirstName"] = txtFirstName.Text;
                items["LastName"] = txtLastName.Text;
                items["Email"] = txtEmail.Text;
                items["Date Of Join"] = txtDOJ.Text;
                items["Sex"] = drpGender.SelectedValue;

                SPFieldUserValueCollection values = new SPFieldUserValueCollection();              
                foreach (PickerEntity entity in myPeoplePicker.ResolvedEntities)
                {
                    SPFieldUserValue fuv = new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt16(entity.EntityData[PeopleEditorEntityDataKeys.UserId]), entity.Description);
                    values.Add(fuv);
                }

                string managers = myPeoplePicker.CommaSeparatedAccounts;
                char[] splitter = { ',' };
                string[] splitPPData = managers.Split(splitter);
                SPFieldUserValueCollection myvalues = new SPFieldUserValueCollection();
                for (int i = 0; i < splitPPData.Length; i++)
                {
                    string loginName = splitPPData[i];
                    if (!string.IsNullOrEmpty(loginName))
                    {
                        SPUser user = web.SiteUsers[loginName];
                        SPFieldUserValue fuv = new SPFieldUserValue(web, user.ID, user.LoginName);
                        myvalues.Add(fuv);
                    }
                }
                /*
                string Assigned = ((Microsoft.SharePoint.WebControls.PickerEntity)(myPeoplePicker.Entities[0])).Key;
                Assigned = Assigned.Remove(Assigned.IndexOf(';'));
                int UserID = Convert.ToInt32(Assigned);
                items["User"] = web.SiteUsers.GetByID(UserID).LoginName;*/

                items["User"] = myvalues;

                items["Marital Status"] = drpMaritalStatus.SelectedValue;
                items["CL"] = 8;
                items["PL"] = 4;
                items["LOP"] = 0;
                items["LastUpdateOn"] = DateTime.Now;
                items.Update();
            }


http://www.sswug.org/articles/viewarticle.aspx?id=43246

Thursday, August 4, 2011

Runtime Error -- Custom Pages

To View Real Error Description in SharePoint 2010:

Open the web.config (“C:\inetpub\wwwroot\wss\VirtualDirectories\<port>”) and set:
1. Debug=”true” instead of the default of Debug=”false”
2. CallStack=”true” instead of the default of CallStack=”false”
3. CustomErrors=”Off” instead of the default of CustomErrors=”On”

Open other web.config (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config) and set:
1. CustomErrors=”Off”