Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
    
Fells like you have not gotten the latest code in the GAC? Check the ULS logs for details about the error –  Robert Lindgren Feb 27 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-b‌​6ab-affe7768265f" –  luckydeveloper Feb 27 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. –  Robert Lindgren Feb 27 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. –  luckydeveloper Feb 28 at 7:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.