Pages

Wednesday, June 17, 2009

How to display users to SharePoint People Picker control and get data from SharePoint People Picker control

In below example, I’ll demonstrate how to display users to people picker web control and get data from the same control. I have field called “Staff Assigned” and its data type is People/Group.

Below code will tell us how we can take data from that people/Group field and display to people picker SharePoint web control and also get data from people picker and give back to people/Group field from object model programmatically.

//Display users from people/Group field to People Picker Control

if (itmAudit["Staff Assigned"] != null)
{
char[] to_splitter = { ';' };
string to_list = itmAudit["Staff Assigned"].ToString(); // Reads value stored in SPList. (i.e., "Domain\User1; Domain\User2")
string[] arr = to_list.Split(to_splitter);
string user = string.Empty;
System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
for (int i = 1; i < arr.Length; i++)
{
if ((i % 2) != 0)
{
user = arr[i].Substring(arr[i].IndexOf("#") + 1);
PickerEntity entity = new PickerEntity();
entity.Key = user;
entity = userPicker.ValidateEntity(entity);
entityArrayList.Add(entity);
}
}

userPicker.UpdateEntities(entityArrayList);

//Save users to people/Group field from People Picker Control

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

values.Add(fuv);
}

itmAudit["Staff Assigned"] = values;

90 comments:

  1. Hey,

    Nice article Disha, actually I was looking for how to take values from SharePoint People Picker control and update those values into SharePoint list columns, and I have found your article, your information is very good and precise also.

    Thanks a lot for the nice information.

    -Sanket

    ReplyDelete
    Replies
    1. Hi Disha,
      My requirement is to populate a Peoplepicker control on change of a dropdown. I have different Departments, displaying in a dropdown. OnSelectedChangedIndex I want to show the contact person name in the people picker control.

      It's settign for the very first time but after that it is showing the old values. Not refreshing the DisplayText name.

      I am new to MOSS 2007, need ur help.
      Thanks in advance.

      Delete
  2. Thanks For the Comment

    ReplyDelete
  3. [...] http://dishashah.wordpress.com/2009/06/18/how-to-display-users-to-sharepoint-peoplepicker-and-to-get... Enjoy!! [...]

    ReplyDelete
  4. Hi Disha,

    I googled and browsed to many pointers. Yours is the most helpful one! The only question I have is: is there any way to check if PickerEntity is a user(people) or a group? I want to save users and groups data in different places.

    Many thanks,

    -HB

    ReplyDelete
  5. Hey HB

    I am glad because it helps you. Thanks for Comment and appreciation.

    Answer of your Question is :

    You can read the resolved users and groups that the user has entered by using the editor's ResolvedEntities property, which is an ArrayList containing a list of PickerEntry objects. Each PickerEntry object contains an EntityData property bag which includes a "PrincipalType" field. You can use this to determine whether the resolved entity is a user or group.


    foreach (PickerEntity entity in pplEditor.ResolvedEntities)
    {
    switch ((string)entity.EntityData["PrincipalType"]) {
    case "User":
    // ... do stuff here ...
    break;
    case "SharePointGroup":
    // ... do stuff here ...
    break;

    }
    }
    Enjoy :)
    Disha Shah

    ReplyDelete
  6. Hi Disha,

    Thank you so much for your help. It works like a charm!

    I got another question about the group users: is it possible to retrieve all users for a given group? Like getting user names for a SharePoint group.

    switch ((string)entity.EntityData["PrincipalType"]) {
    case “SharePointGroup”:
    //SPUserCollection users = GetUsersByEntity(entity);
    //List users = GetGroupUsers(groupName)
    break;
    }

    Thanks again!
    HB

    ReplyDelete
  7. Yes HB, everything is possible in this world :) just we need to see which solution fits for our requirements.

    You can try below code to get list of users from SharePoint group.

    case "SharePointGroup":

    if (entity.EntityData.ContainsKey("SPGroupID"))

    {

    int groupID = int.Parse((string)entity.EntityData["SPGroupID"]);
    SPGroup group = web.Groups.GetByID(groupID);
    foreach (SPUser user in group.Users)
    { //Do Stuff }

    }

    break;

    Thanks

    Disha Shah

    ReplyDelete
  8. Hi Disha,

    Thank you for you answer! I got it work with your help. One thing I need to change is using web.SiteGroups instead of web.Groups, which throw a "Group cannot be found" exception at run time.

    Wish you have a nice weekend!

    HB

    ReplyDelete
  9. HB,

    It's good to hear that it helped you..

    You too also have a great weekend ahead !!

    -Disha Shah

    ReplyDelete
  10. Hi Disha,

    Your article is really very useful to me. Appreciated.

    One more thing i would like to know that How to make 'read only' people picker in custom list. I tried a lot but i could not find a solution even I have tried using objField.ReadOnlyField = true; but it hides this entire field.

    Regards,
    Viraj Vashi

    ReplyDelete
  11. Viraj,

    Thank you very much for the appreciation.

    Can you please let me know what do you mean by "making read only people picker into list" ? Are you trying to do that end user won't able to enter/select any value/users into people picker control?

    "objField.ReadOnlyField = true" comes with SPField object, if you want to make people picker in read only mode then you can write "peoplepickerctl.Enabled = false", so end user can't type anything into people picker control.

    Please let me know if you are looking for something else.

    Thanks, Disha Shah

    ReplyDelete
  12. Hi Disha,

    Thank you very much. I was looking exactly you have sent to me.

    Regards,
    Viraj Vashi

    ReplyDelete
  13. Hi Disha,

    Thank you very much for spent your important time for me.

    I have one more query which is:

    I have one custom list whose name is 'Defects' and in that custom list i have one lookup control whose name is 'Project Name'(Which comes from Project details list) and one more column i have which is 'Assigned To'(which is people picker). I want to display display users in 'Assigned To' column based on Project name column.

    For better understanding...
    Project name: Lookup control(Dropdown list)
    Assigned To: People picker

    I hope you will understand my problem.

    I would be appreciated your help.

    Regards,
    Viraj Vashi

    ReplyDelete
  14. Viraj,

    As per your requirements, you are saying that depends on Project name you need to display assigned to value, it implicitly says that you must have column either in Project List as "Assigned to" or you have a new custom list which has "Project Name" and "Assigned To" column. I mean you need some type of mapping between those two columns.

    Now how you fill "Assigned to" depends on "Project Name" column, right?

    Well you can use a custom web part and write an event handler based on "Projectname_selectedindexchanged" and use SPquery to find the "Assigned To" field and assign value into your web part.

    Second option, if you don’t want to write web part then you can use event handler as "Item Added" and fill the value of "Assigned To" and display the value.

    Hope this helps!

    Thanks,
    Disha

    ReplyDelete
  15. Thank you very much for quick reply.

    You understood perfectly my question.

    I agree with you first option and i tried also but i can not go with first option.

    In second option,as you said that i need to write in "Item Added" event but it only fires when we click on OK button right?
    Both columns are in same custom list and I want respective value of people picker control based on dropdown list of lookup control(project name). (Same like selected index changed event in ASP.net)

    I am explaining you in details:
    Suppose in project name there are: ERP System,Hospital Mgt etc(which binds from 'project' custom list) data. If user will select ERP system then in people picker their project owner's value will come means ERP System's project owners will display. Eg. Viraj Vashi;Abc; are project owner of ERP sytem.

    Hope you have clearly understood.

    Thanks in advance.

    Regards,
    Viraj Vashi

    ReplyDelete
  16. Viraj

    It is like when a person selects "Country" from user interface we need to display "States" related to that "Country" .(Filter from Country)

    Now if you cannot go with the first option, then I can suggest about use "Custom Field Controls". It will fulfill your requirement, because I couldn't find a way to do this out of the box.

    But you need to decide which way you want to go ahead

    If I am at your place then If I need to do this kind of thing Project name-->Assigned to only once ,then I will go with webparts and If I have to use multiple times ,then I will go with custom field controls.

    This is very useful link how to create and deploy custom field controls
    http://datacogs.com/datablogs/archive/2007/08/26/641.aspx.

    Hope this helps..

    Disha Shah

    ReplyDelete
  17. The code works well for displaying and saving however when i use the save method:
    //Save users to people/Group field from People Picker Control

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

    values.Add(fuv);
    }

    itmAudit["Staff Assigned"] = values;

    I get ERROR
    Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

    any advice would be greatly appreciated!

    ReplyDelete
  18. Sorry, to claify i am using the save mehtod on spitem update and am getting the error. No errors on spitem add.

    ReplyDelete
  19. Hey Nick

    Can you try one thing first for me?

    Update that list item by SharePoint list user interface not from object model code.

    Go to that list and edit any item and save it. Check whether that error comes or not?

    Even this error also new to me...I just goggle it and I found related links...Can you please go through that?

    http://sharepointbergen.blogspot.com/2007/04/customizing-andor-extending-or.html

    http://blogs.msdn.com/circularfile/archive/2008/06/11/unexpected-sharepoint-list-definition-behavior.aspx

    http://www.codeproject.com/Messages/3187992/Re-Catastrophic-failure-Exception-from-HRESULT-0x8.aspx

    According to all links, there are some possibilities like error in Schema.xml if you create that list as feature.

    Hope this helps!!!!!

    Best Regards
    Disha Shah

    ReplyDelete
  20. Hi Disha,

    I appreciated your quick reply.

    I have gone through your all helpful links but unfortunately i could not find the solution which i was looking for. If possible then kindly send me the steps and code for atleast state and city custom field control.

    I would be very thankful to you.

    Regards,
    Viraj Vashi.

    ReplyDelete
  21. Hi Disha,

    I tried it but i am also getting same error.

    Regards,
    Viraj Vashi

    ReplyDelete
  22. Hey Viraj

    I am planning to write article related to custom field type, it is under construction and will take some time to finish it.

    Mean while, Please go through below links, which will helpful for you to start your development work for custom field type.

    http://vspug.com/nicksevens/2007/08/31/create-custom-field-types-for-sharepoint/
    http://msdn.microsoft.com/en-us/library/bb684919.aspx

    Thanks,
    Disha Shah

    ReplyDelete
  23. Hey Viraj

    Can you try one thing first for me?
    Update that list item by SharePoint list user interface not from object model code.
    Go to that list and edit any item and save it. Check whether that error comes or not? Can you please let me know outcome whether error comes or not?
    Can you tell me you deployed that list on that site collection with feature or you created as a custom list from SharePoint user interface?

    Please provide me with these two information...So I can get some direction.

    Thanks
    Disha Shah

    ReplyDelete
  24. Hi Disha,

    I am sorry to say that but i did not get you.Can you please explain me in details? Actually I don't know What is SharePoint list user interface?

    Regards,
    Viraj Vashi

    ReplyDelete
  25. Viraj,

    SharePoint list user interface means, open your SharePoint site into browser, go to your custom list, click on "New" button and try to enter some data into user interface and clicks on “save” button to see whether you are getting error or not?

    If you are not clear, then please start new thread for comments with detail description, actually I am also confused that for which thread you wrote “I tried it but i am also getting same error”

    Thanks,
    Disha

    ReplyDelete
  26. Viraj,

    I have written article on how to create custom field type, please go through this link, it will describes you each steps.

    http://dishashah.wordpress.com/2009/11/05/step-by-step-tutorial-for-how-to-create-and-implement-custom-field-type-in-sharepoint/

    ~Disha Shah

    ReplyDelete
  27. Hi Disha,

    Thank you for explained me Sharepoint list user interface.

    I have tried the same but i have not got any errors.

    It saved without any error.

    Regards,
    Viraj Vashi

    ReplyDelete
  28. Hi Disha,

    I have one query related with people picker.
    I want to allow to search only those users who are assigned for respective project in people picker.
    I am explaining you my requirement in details:
    I have tow custom lists.
    One is CustomList_Project:
    In CustomList_Project custom list, i have following columns:
    1) Project name: Textbox(User enter project name)
    2) Assigned To: People picker(User assigned for this project)

    Second is: CustomList_Second
    1) Project name(which is lookup control and whose values come from CustomList_Project(which is custom list)
    2) GetProjectOwner : People picker: When i select project name then it would only allow to search those users who have assigned for this project.
    (By default it is comming all users)

    I know that this is quite difficult query but i am sure that as per your knowledge and experience in sharepoint it would not be difficult to solve this.

    Regards,
    Viraj Vashi

    ReplyDelete
  29. Viraj

    Here are some ideas which comes into my mind, from where you can achieve your functionality.

    #1 ) You can write event handler on “CustomList_Project” list and when you add/insert new project name and assigned to fields, create new SharePoint Group named with “project name” and add/insert assigned to user into SharePoint group as Users.


    Now when you are looking for project name into “CustomList_Second” list, on post back of current page, search/find for “project name” into all SharePoint group and assign that SharePoint group name into People Picker Property of “GetProjectOwner’ field, in these way – you can see only users which has been added to SharePoint group name (as per you - search those users who have assigned for this project), instead of all users.


    #2) Change your interface slightly - Instead of GetProjectOwner as People picker control, put drop down box for GetProjectOwner field, and write code in which when user select Project name into “CustomList_Second” list then search for same project into “CustomList_Project “ list and take “Assigned To” value and populate into GetProjectOwner drop down box.

    Hope you will get some answer from these points.

    Thanks,
    Disha

    ReplyDelete
  30. Hi Disha,

    Thanks a lot for your reply.

    Disha, Actually I want exactly the same which you have written in #2)point in reply. I also want to achieve this thing but it is separate requirement. Do you have any idea how to populate dropdown list based on CAML query condition. Eg.
    SPList lstCommunity = web.Lists["Community"];
    SPQuery qry = new SPQuery();
    qry.Query = "" + CommunityId + "";
    DataTable dtCommunity = lstCommunity.GetItems(qry).GetDataTable();

    Now I want to display datatable value in dropdownlist so tell me how to achieve this or you can give other example of CAML query with dropdownlist or lisbox control.

    Now i am comming with my people picker requirement, which is either i could not explain you properly or you could not understand properly.
    Disha, Actually i want to allow only those users who have assigned for that project and i must have to use people picker for that. Eg. User will type "Viraj Vashi" in people picker and Viraj Vashi user is available but it should not allow to search only when it is assigned for that project means when user type "Viraj Vashi" in people editor that time it should show message like "invalid user or this user is not allowed for this project". Hope now you have understood properly.

    Regards,
    Viraj Vashi

    ReplyDelete
  31. Viraj

    Example of SPQuery:

    SPList objList = SPContext.Current.List.Lists[“ListName”];
    SPQuery strquery = new SPQuery();
    string Query = string.Empty;
    Query = "OrderBy" +

    "FieldRef Name='FileLeafRef'" +

    "OrderBy" +

    "Where" +

    "Eq" +

    "FieldRef Name='DocIcon' " +

    "Value Type='Text' xml Value" +

    "Eq" +

    "Where";


    strquery.Query = Query;
    SPListItemCollection objListItemColl = objList.GetItems(strquery);
    cmbList.DataSource = objListItemColl;
    cmbList.DataTextField = strDataTextField;
    cmbList.DataValueField = strDataValueField;
    cmbList.DataBind();

    NOTE: somehow, special characters are not being display into query, write query as per your requirements.

    On first look only, I understand your People picker requirements, and given the options/ideas what I was thinking about regarding alternate solutions.

    Thanks,
    Disha Shah

    ReplyDelete
  32. Hey Disha,

    Thank you very much. I was exactly looking the same. Amazing!

    If possible then please try to find out about people picker requirement.

    I understand that it is difficult to achieve but i am sure that you would find any alternate solution.

    Regards,
    Viraj Vashi

    ReplyDelete
  33. Hi Disha

    Im new to share point .Just have 1 year exp in ASP.net(C#).Can u please give me the links of the resourses where i can start learning sharepoint,which can give complete understading of sharepoint.

    It will be really helpful

    ReplyDelete
  34. Narpal

    It is good to hear that you want to start Sharepoint.

    You can download "Software Development Kit" for Windows Sharepoint Service and Microsoft Offfice Server 2007 from microsoft, which gives you detail explanation for every componene of Sharepoint

    Here are the links!!!!

    http://www.microsoft.com/downloads/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en
    http://www.microsoft.com/downloads/details.aspx?familyid=05e0dd12-8394-402b-8936-a07fe8afaffd&displaylang=en

    Hope you can start on this!!!!

    Thanks
    Disha Shah

    ReplyDelete
  35. I'm Creating Task[list] in object model whenever request[List] is created. I'm sending mail to Admin Group related to request raised[raised request is task to admin,lets assume]. I'm able to send mails to Admin group but I want to send the link in mail so that on clicking that link he will login and will go to that particular task and will do the stuff there.


    how can i do that .I hope i have express the problem rightly.

    ReplyDelete
  36. Hi Disha

    I’m Creating Task[list] in object model whenever request[List] is created. I’m sending mail to Admin Group related to request raised[raised request is task to admin,lets assume]. I’m able to send mails to Admin group but I want to send the link in mail so that on clicking that link he will login and will go to that particular task and will do the stuff there.

    how can i do that .I hope i have express the problem rightly.

    ReplyDelete
  37. Hi Disha
    i am new to sharepoint.having 1 yr experience in asp.net(c#).
    can u suggest some tips regarding sharpoint custom controls .

    ReplyDelete
  38. Narpal

    According to my understanding, you want to send link for created a new task into email.

    If yes then you can write this in your code to achieve that:

    SPContext.Current.Web.Url + "/Lists/" + SPContext.Current.Web.Lists["Tasks"].Title + "/DispForm.aspx?ID=" + itmTask.ID.ToString();
    Thanks,
    Disha Shah

    ReplyDelete
  39. Babu

    Good to hear that you want to start with SharePoint. But I am little bit confused - what do you mean by SharePoint Custom Control?

    Do you mean by Custom web parts or something else?

    Please elaborate on what exactly you are looking for.

    Thanks
    Disha Shah

    ReplyDelete
  40. Hi Disha

    Thanks for Ur solution.Really You are helping alot to New people in share point.I have a query and i will be delighted if i get quick reply.I have to display dash board (Bar chart) using external datasource.can u please explain or give some respective link .

    ReplyDelete
  41. Hi Disha,
    Thank you for you Quick Reply,Your R Correct I Am Asking About Share point Custom Web parts.
    Babu

    ReplyDelete
  42. Babu

    The best Example step by step for creating webpart is

    http://msdn.microsoft.com/en-us/library/ms452873.aspx
    http://www.wrox.com/WileyCDA/Section/Developing-SharePoint-2007-Web-Parts.id-306330.html

    Start on this, and then you can have better idea about webpart.

    Hope this helps

    Thanks
    Disha Shah

    ReplyDelete
  43. Narpal,


    It seems that Santosh, you and Babu are doing some type of competition; sometime you all have same type of requirements :)

    You can also refer same links which I sent to Santosh and you can also do one thing over here, if you want to use external data source into Dashboard, then use BDC functionality and take external data source into SharePoint List and then use SharePoint list as source for displaying Dashboard.

    Thanks,
    Disha

    ReplyDelete
  44. here is how you assign a value to sharepoint people picker.. http://sharepointforums.blogspot.com/2009/08/adding-value-to-peoplepicker-using-code.html

    ReplyDelete
  45. hi disha

    its very urgent

    i am getting this error please look in to it.

    when publishing the infopath form .am giving correct webserver name but still it is showiing same error .

    infopath cannot find or cannot access the following webserver:http:share:2113
    make sure that the webserver name is valid ,that your proxy settings are correct,and that you have the necesary
    permissions to publish to this library

    ReplyDelete
  46. Hi Ajay

    Can you please let me know which version of InfoPath are you working on?

    You can also follow this Microsoft article: http://support.microsoft.com/kb/925431


    When you publish a form to a form library you need to make sure that you have the correct address where you have created the form library.
    For example you have form library in http://webserver/sites/test that is the address you put in when publishing the form. I have observed that your server name is incorrect, hope you are giving your server name as “http://share:2113”

    Things need to check: you also have the ability to create form library through InfoPath which is recommended also check that you are running InfoPath forms with the user who has proper privileges.

    Hope this helps.

    Thanks,
    Disha Shah

    ReplyDelete
  47. The code is not working for me for some users.

    SPFieldUserValue fuv = new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt16(entity.EntityData[PeopleEditorEntityDataKeys.UserId]), entity.Description);

    When i debug, I found that for some users PeopleEditorEntityDataKeys.UserId is null.

    Could you please help me

    ReplyDelete
  48. Susa,

    Add this condition before taking fuv value

    if (entity.IsResolved == true)

    After adding the condition code looks like as following:

    SPFieldUserValueCollection values = new SPFieldUserValueCollection();

    foreach (PickerEntity entity in userPicker.ResolvedEntities)

    {

    if (entity.IsResolved == true)



    {

    SPFieldUserValue fuv = new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt16(entity.EntityData[PeopleEditorEntityDataKeys.UserId]), entity.Description);



    values.Add(fuv);

    }

    }

    UserId is null because one possibility is that users are not part of your SharePoint application means they are not added in People who can access the site.

    Hope this helps,

    Disha Shah

    ReplyDelete
  49. Hi Disha

    i have one unique requirement, do you know can we use People picker contral on custom ASP.NET page using Visual Studio 2005/2008?.

    -Jimmy

    ReplyDelete
  50. Jimmy

    You want to create ASP.NET Custom page for SharePoint site? If yes you need to add 2 tags in your .aspx page

    1> Register Tagprefix="SharePoint"
    Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=12.0.0.0,
    Culture=neutral, PublicKeyToken=71e9bce111e9429c"


    2> wssawc:PeopleEditor
    AllowEmpty="true" Width="70%" ShowEntityDisplayTextInTextBox="true"
    ValidatorEnabled="true"
    id="userPicker" CssClass="drpClass"
    runat="server" CommaSeparatedAccounts=","
    ShowCreateButtonInActiveDirectoryAccountCreationMode="true"
    SelectionSet="User"

    and to get and save data to people picker you can refer the blog.

    Hope this helps!!!

    NOTE: I did not use some characters because it does not accept and behaves unexpectedly , I hope you can identify and put starting and closing end to both lines.
    Thanks
    Disha Shah

    ReplyDelete
  51. I'd like to mention that your code resolved an issue I had about non admin users being unable to add a listitem containing a people field using the "EnsureUser" syntax. Using the "SPFieldUserValue" collection and assigning values using the "PeopleEditorEntityDataKeys" class resolved it. Thanks!

    ReplyDelete
  52. Chetan

    It is good to hear that this blog helps you out to solve your problem. Thanks for your time to leave comment and appreciation

    Thanks
    Disha Shah

    ReplyDelete
  53. I have created one site in sharepoint in this poeple and group picker does not getting some of user of our domain.

    But at the default sharepoint site all user come in people and group picker.
    please help

    ReplyDelete
  54. Altaf

    Can you please elaborate your question in more detail? When and What are you doing so that you have knowledge that People Picker does not show all users in that Sharepoint Site.

    Just one guess.
    Please check the People Picker Column Settings, that you selected all Users or SharePoint Group?

    Best Regards
    Disha Shah

    ReplyDelete
  55. Hi Disha, great work

    well, I kinda have the same question here, I ve been trying to set the people picker in a form as readonly, because I want my user to see the values I prepopulated it with, but I dont want them to change it....

    do you have a solution for this problem??? I have tried many different solutions, but nothing works for people picker.

    ReplyDelete
  56. Hi Manuel
    Thanks for valuable comment.

    You can use enabled property of peopleeditor and set as "false" , I tried and everything is working the way you want. Browse button is also disabled.

    Hope this helps
    Disha Shah

    ReplyDelete
  57. Hi Disha,

    Thanks a lot for sharing this article, its fulfill my project requirement .

    thanks once again.


    Regards
    Mansoor

    ReplyDelete
  58. Hi Disha,

    can you help on my requirement, that is Cascading drop down list.the below link exact same as my requirement.but

    http://datacogs.com/datablogs/archive/2007/08/26/641.aspx

    when i change the list names and column names instead of countries,cities,country,city it wont work ?

    any suggestion plz...! waiting ur reply..

    Regards
    Mansoor

    ReplyDelete
  59. Hi Mansoor

    Thanks for appreaciation about blog.

    Can you please let me know about what error is given by the code when you change with the Field and list names? So it will be helpful for me to solve out the error.

    Thanks & Regards
    Disha Shah

    ReplyDelete
  60. Hi Disha,

    can you help on my requirement, that is SharePoint Desginer to send an attachement to users.I googled this requirement but not getting my requirement.
    please help me this requiremnt ,
    thanks in advance

    any suggestion plz…! waiting ur reply..


    Thanks & Regard
    vinesh

    ReplyDelete
  61. hi disha,
    i am creating a task list but not using object code. i ve a manager field in the list which is people picker control . i have one more dropdown list where approve is one of the option. my requirement is only manager should approve the form. so i need to compare manager with current user. can u please suggest me some code and pls tel me where do i insert that code..

    ReplyDelete
  62. Hi

    Can you please let me know when manager should approve the form? He got that information via email or what?

    It helps me to provide you the correct answer if you give me full description of the requirement.

    Thanks
    Disha Shah

    ReplyDelete
  63. Hi Disha,

    I have one people picker cotrol on my SharePoint Form. I just want to set and get the value from that people picker control
    I need to do this on event handler using c# code .
    any idea ?

    ReplyDelete
  64. Hi

    Yes you can do that in event handler code too in C#.

    The code which is inside the Post, you can use in event handler with changes depends on your event handler eventtype and some properties.

    Thanks
    Disha Shah

    ReplyDelete
  65. Hi Disha,
    Its Nice article.
    But i m new with the infopath.
    and i will tell you the my sinario that i have to implement.
    i have design the infopath form which consist of person picker control. Now i want to send this value to "Assign To" column of sharepoint list.(the data type of Assign To is Person picker)
    Can u mail me the step by step procedure to achive this.
    Thanks

    Ujwal

    ReplyDelete
  66. Hi Ujwal

    In Inforpath ,We can use ContactSelector which has same kind of functionality as People Picker control in SharePoint.

    There are some links which are really very useful
    http://www.sharepointassist.com/2009/02/27/adding-a-contact-selectorpeople-picker-to-an-infopath-form/

    Please go through with the below link which gives you nice overview for PeoplePicker control with the use of Activex Control
    http://metahat.blogspot.com/2007/05/people-picker-control-for-infopath-2007.html

    If you stuck please let me know!!

    Thanks,
    Disha Shah

    ReplyDelete
  67. Hi Disha,
    Thanks very much to share the knowledge with us.
    It helps me a lot.
    I have one question.
    I have one shareport list and there is one column called 'Manager' in that list. The type of this column is 'Single line of text'. Now i want to change the column type to 'Person or Grou'. But i notced that we cant change the type to Person and Group because the option is not present.
    Can you please tell me how can i change the type of column without deleting the column? Or else it is necessary to delete the column?

    Thanks again for this blog.
    - Kaustubh.

    ReplyDelete
  68. Hi Kaustubh

    Thanks for appreciation. No you do not have any other option rather than deleting that column and create a new one.

    Thanks
    Disha Shah

    ReplyDelete
  69. Hope might helpful this to you.
    http://sharepoint2010learnersworld.blogspot.com/2011/07/how-to-validate-users-in-sharepoints.html

    ReplyDelete
  70. Hi disha,

    I have created an Issue list with Title, Comments, Assigned To, and Status columns. I want to insert/update a list item to this issue list using Application page.

    My questions are:

    1. What controls i can use for Status and Assigned To field?

    2. How can i populate the values for Status and Assigned To field?

    Can you provide some sample code to do this?

    Thanks in advance,

    Abirami

    ReplyDelete
  71. Abirami

    You can use SharePoint Controls to do this , name of sharepoint control is "FormField".

    When you use "FormField" sharepoint control, you do not need to worry about which type of control you will put, it will automatically take care of this.

    Some lines of code which might help you...

    foreach (SPField field in lst.Fields)
    {
    ////

    ListField = new FormField();
    ListField.FieldName = field.Title;
    ListField.ControlMode = SPControlMode.New;

    ListField.ListId = lstCourseCreditRequirements.ID;
    ListField.ID = field.Title;
    this.Controls.Add(ListField);
    ////
    }


    Hope this helps!!!
    Disha Shah

    ReplyDelete
  72. Hi Disha ,

    Thanks for the great article..really hekped me a big deal.

    Question- Is it possible to use sharepoint to linq to save the values from the people picker to a people column in a sp List

    ReplyDelete
  73. Hi Martin

    Sorry for the late reply.

    Yes you can save values from people picker to a people column via SharePoint LINQ.

    may be this piece of code may help you

    public void AddUserToList()

    {

    var ctx = new SiteLinqDataContext(WebUrl);

    SPUser usr = null;

    using (SPSite site = new SPSite(WebUrl))

    {

    using (SPWeb web = site.OpenWeb())

    {

    usr = web.EnsureUser("domain\\account ");

    }

    }

    if (usr != null)

    {

    TaskDemoItem newItem = new TaskDemoItem()

    {

    AssignToId=usr.ID,

    Title="Hello"

    };

    ctx.TaskDemo.InsertOnSubmit(newItem);

    ctx.SubmitChanges();

    }

    }

    Thanks
    Disha Shah

    ReplyDelete
  74. Hi Disha,

    Thanks for your detailed sample...plis bear with me, how can I save multiple entries from a peoplepicker to a people column on a sp list

    Regards,

    Martin

    ReplyDelete
  75. Hi Disha,
    Hoa can i keep the values in People Picker even though the page gets postback.

    ReplyDelete
    Replies
    1. Hi Mohan

      May be this link will help you.
      http://berg-henry.blogspot.com/2010/04/get-value-of-peoplepicker-during.html

      Disha Shah

      Delete
  76. HI Disha,
    Can you help me in one requirement

    ReplyDelete
    Replies
    1. Hi Sudhanshu

      What is your requirement?

      Please describe!!!

      Disha Shah

      Delete
  77. but plz reply
    sudhanshu.sharma@lntinfotech.com

    ReplyDelete
  78. beautiful, you saved me a lot of time and headache!

    ReplyDelete
  79. Thats great blog... help me alot... thanks Disha.....

    ReplyDelete
  80. hi disha
    i have created custom people editor and want to remove Account Name,Department column from picker dialog, here is my people picker code


    userSelect = new PeopleEditor();
    pickerEntity = new PickerEntity();


    userSelect.MultiSelect = true;
    userSelect.AllowEmpty = false;
    userSelect.AutoPostBack = false;
    userSelect.PickerDialogToolTip = "Select the User to get Alerts";
    userSelect.PlaceButtonsUnderEntityEditor = true;
    userSelect.ID = "PeopleEditor";
    userSelect.MaximumEntities = 5;
    userSelect.SelectionSet = "User,SecGroup";


    userSelect.Rows = 1;



    this.Controls.Add(userSelect);

    ReplyDelete
    Replies
    1. Hi Vishal

      Please check this as refecrence
      http://panvega.wordpress.com/2008/02/22/custom-sharepoint-people-picker/

      In this blog, at the button click event,check these lines
      if (pickEn.IsResolved)
      {
      builder.AppendLine(pickEn.DisplayText);
      builder.AppendLine(pickEn.Description);
      builder.AppendLine(Convert.ToString(hstEntityData["DisplayName"]));
      //string email = Convert.ToString(hstEntityData["Email"]);
      //string loginName = pickEn.Key;
      builder.AppendLine(Convert.ToString(hstEntityData["SPUserID"]));
      //string department = Convert.ToString(hstEntityData["Department"]);
      builder.AppendLine(Convert.ToString(hstEntityData["PrincipalType"]));
      //string sIPAddress = Convert.ToString(hstEntityData["SIPAddress"]);
      //string title = Convert.ToString(hstEntityData["Title"]);
      }

      Hope this helps!!
      Disha Shah

      Delete
  81. hey....
    Im trying to use a people picker control in my own web part... if you had seen sharepoint 2013 there is a people picker control which drops down suggestions when a name is typed..

    I want to add a control which would do that..(drop down users names while someone types on it)
    i have raised this issue in many places but no didnt get a proper answer...
    hope you could help me..

    Thankz
    Danister

    ReplyDelete
  82. Hi Disha,

    I have a people Picker control in my List. I am using a timer job to send email to the user who is picked up in the pople picker. If it is of one user i can get like this.

    private void GetNameAndEmailFromPeoplePicker(SPListItem mySourceListItem, out String PeoplePicker, out String CCPeoplePicker, out String UserName)
    {
    PeoplePicker = "";
    CCPeoplePicker = "";
    UserName = "";
    try
    {

    SPFieldUserValueCollection Users = new SPFieldUserValueCollection(mySiteWeb, Convert.ToString(mySourceListItem["Point of Contact"]));
    foreach (SPFieldUserValue User in Users)
    {
    UserName = User.User.Name;
    PeoplePicker = User.User.Email;
    }
    SPFieldUserValueCollection BCCUsers = new SPFieldUserValueCollection(mySiteWeb, Convert.ToString(mySourceListItem["Backup Point of Contact"]));
    foreach (SPFieldUserValue BCCUser in BCCUsers)
    {
    CCPeoplePicker = BCCUser.User.Email;
    }
    }

    catch (Exception ex)
    {
    UlsLogs.LogErrorInULS(ex.InnerException.ToString(), TraceSeverity.High);
    }
    }

    Can you please provide me a method or modify this method to reterive multiple users,Active directory group,Sharepoint Group picked up by the people picker control in sharepoint list
    Thanks,
    Sandy

    ReplyDelete
    Replies
    1. Hi Santosh

      Isn't my code wokring for taking the users from people picker?

      You would use my code to get user name from People Picker and find the user from SPWeb and then use SPUser object to get its Email-ID and attach properties!

      Let me know if you have any questions!

      Thank You
      Disha Shah

      Delete
  83. Hi,My thoughts on this will differ depending on the purpose of the web page. I my opinion the best Web Design Cochin is a design that will accomplish the page's goal with the least amount cost and time to develop.Thanks........

    ReplyDelete
  84. Hi Disha
    How to display a list column "Assigned To" value Which is a people picker in a grid view.

    Thanks

    Richa

    ReplyDelete