1

I have created a SharePoint visual webpart in SharePoint 2010 where i am using SharePoint people picker to enter the SharePoint user but when i submit.It throws an unexpected error.

here is my .ascx code

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

 <SharePoint:PeopleEditor  AllowEmpty="false" ValidatorEnabled="true" ID="pplprimarycontact"
                runat="server" MultiSelect="false"  SelectionSet="User" />


and this is my code behind .ascx.cs code

protected void Button1_Click(object sender, EventArgs e)
        {
            string group_name;
            bool user_exists_in_the_group = false;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {

                            PickerEntity pe = (PickerEntity)pplprimarycontact.Entities[0];
                            string u1 = pe.Description;
                            SPUser user = web.EnsureUser(u1);
                        }
                        catch(Exception ex)
                        {
                         }
                    }
                }
             });
        }


on button click it directly throws "an unexpected error has occurred" message i.e even when i am debugging putting breakpoint at the start of button click the breakpoint does not hit.
i figured out that it can be people editor issues, because when hard-coded the user as follows, it worked without throwing any error.

 //PickerEntity pe = (PickerEntity)pplprimarycontact.Entities[0];
                            //string u1 = pe.Description;
                            string u1=@"domain\name";
                            SPUser user = web.EnsureUser(u1);


Anyone any ideas? , thank you

4
  • Fells like you have not gotten the latest code in the GAC? Check the ULS logs for details about the error Feb 27, 2014 at 10:53
  • i got this error in the logs "Failed to find the XML file at location '14\Template\Features\HideRibbon_SHRHideRibbon\feature.xml' e4660c06-9505-41e7-b6ab-affe7768265f" Feb 27, 2014 at 11:13
  • Looks unrelated to this; you have probably retracted a solution containing that feature. It has nothing to do with your peoplepicker though. Feb 27, 2014 at 11:24
  • My code was correct, there was some issue with the SharePoint site collection this same code worked with another site collection. Thank you anyways. Feb 28, 2014 at 7:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.