looping through values in a people editor controls

Last post 07-22-2009 6:24 AM by ghostme. 6 replies.

Sort Posts:

  • looping through values in a people editor controls

    07-11-2009, 11:21 AM
    • Member
      5 point Member
    • ghostme
    • Member since 10-02-2007, 11:31 AM
    • Posts 35

    Hello guys,

    I am building a custom application that uses a peopleeditor to select people and send email to them.

    My problem is reading the values from the people editor control and send emails to these people.


    Please assst

  • Re: looping through values in a people editor controls

    07-11-2009, 12:54 PM
    • Participant
      1,434 point Participant
    • krunal.shah
    • Member since 04-03-2009, 11:24 AM
    • india
    • Posts 224

     Hi,

    you can get entries from peopleeditor control like this,

    if(PeopleEditor1.Accounts.Count > 0)
        {

          for (int i = 0; i < PeopleEditor1.Entities.Count; i++)
          {

             ArrayList aAccount = new ArrayList();
             aAccount = PeopleEditor1.Accounts;
             PickerEntity pickEn  = (PickerEntity)PeopleEditor1.Entities[i];
             Hashtable hstEntityData = pickEn.EntityData;
             string strEmail = strEmail + ";"+ Convert.ToString(hstEntityData["Email"]);

         }
        }

    then you can split strEmail by ';' so yu will have the email addresses entered in the people editor control.

     

    Thanks,

    Krunal.

     

     

     

    Thanks,
    Krunal
    Please Mark as answer if it helps.it will help others to find the solution.
  • Re: looping through values in a people editor controls

    07-18-2009, 1:48 PM
    • Member
      5 point Member
    • ghostme
    • Member since 10-02-2007, 11:31 AM
    • Posts 35

    Hi Krunal,

    Thanks alot for the code and sorry I haven't replied earlier. Now I have tried your code using an button handler.

    Such as this:

    protected void sendButton_click(object sender, EventArgs e)
            {
                if (inviteesName.Accounts.Count > 0)
                {
                    for (int i = 0; i < inviteesName.Entities.Count; i++)
                    {
                        ArrayList aAccount = new ArrayList();
                       aAccount = inviteesName.Accounts;
                       PickerEntity pickEn = (PickerEntity)inviteesName.Entities[i];
                        Hashtable hstEntityData = pickEn.EntityData;
                        //strEmail = strEmail + "," + Convert.ToString(hstEntityData["Email"]);
                        strEmail = strEmail + Convert.ToString(hstEntityData["Email"]);
                        String[] emailAddress = strEmail.Split(";");
                                            foreach (string email in emailAddress)
                        {
                            messages.Text+=email;
                            
                        }
                    }
                }
            }

    Now I used the above with two account inserted in the people and when I click on the button duplicates values are displayed in the browser.

    Also, aAccount variable was initialized but never used why?

  • Re: looping through values in a people editor controls

    07-19-2009, 7:32 AM
    • Participant
      1,434 point Participant
    • krunal.shah
    • Member since 04-03-2009, 11:24 AM
    • india
    • Posts 224

    Hi,

    The duplicate values are because of the  your "foreach" loop is inside the first "for" loop. you have to move it outside the "for" loop.

    and you can remove this lines from your code,

    ArrayList aAccount = new ArrayList();   

    aAccount = inviteesName.Accounts;  

    i have used it just  to get Accounts in the peopleditor control.

     

    Thanks,

    Krunal.

    Thanks,
    Krunal
    Please Mark as answer if it helps.it will help others to find the solution.
  • Re: looping through values in a people editor controls

    07-20-2009, 3:24 AM
    • Member
      5 point Member
    • ghostme
    • Member since 10-02-2007, 11:31 AM
    • Posts 35

    Hi Krunal,

    Thank you once again for your reply. I have sorted the duplicates as instruction, now I am adding the send email class to the code. However, I observe that while debugging the strEmail variable has a preceeding ";" character which makes the send email class throw an error The parameter 'address' cannot be an empty string.


    Here is my code:

      protected void sendButton_click(object sender, EventArgs e)
            {
                if (inviteesName.Accounts.Count > 0)
                {
                    for (int i = 0; i < inviteesName.Entities.Count; i++)
                    {
                        
                       
                        PickerEntity pickEn = (PickerEntity)inviteesName.Entities[i];
                        Hashtable hstEntityData = pickEn.EntityData;
                       string  strEmail = Convert.ToString(hstEntityData["Email"]);
                       
                         strEmail=strEmail+";" + Convert.ToString(hstEntityData["Email"]);
                        String[] emailAddress = strEmail.Split(';');
                     
    
                      
    
                        // String[] emailAddress=strEmail.Split(new  char[] {','});
                       
                    }
                    foreach (string email in emailAddress)
                    {
    
                        MailMessage msg = new MailMessage();
    
    
                        msg.To.Add(email);
    
    
                        msg.From = new MailAddress("shola007@projectserver01.local");
    
                        msg.Subject ="My 40th Birthday";
    
                        msg.Body = description.Text;
                        
    
                        SmtpClient smtp = new SmtpClient("moss.projectserver01.local");
                        smtp.Send(msg);
    
    
                    }
                }
            }

    Please help

  • Re: looping through values in a people editor controls

    07-22-2009, 3:19 AM
    Answer
    • Participant
      1,434 point Participant
    • krunal.shah
    • Member since 04-03-2009, 11:24 AM
    • india
    • Posts 224

    Hi,


    sorry for late reply, you can do it like this,

    1. protected void sendButton_click(object sender, EventArgs e)  
       2.       {  
       3.           if (inviteesName.Accounts.Count > 0)  
       4.           {  
                        string  strEmail = "";
       5.               for (int i = 0; i < inviteesName.Entities.Count; i++)  
       6.               {  
       7.                     
       8.                    
       9.                   PickerEntity pickEn = (PickerEntity)inviteesName.Entities[i];  
      10.                   Hashtable hstEntityData = pickEn.EntityData;  
      11.                  string  strEmail = Convert.ToString(hstEntityData["Email"]);  
      12.                    
                           if(strEmail != "")
                {
                    strEmail=strEmail+";" + Convert.ToString(hstEntityData["Email"]);  
                }
                else{
                    strEmail = Convert.ToString(hstEntityData["Email"]);
                }
      13.                    
      14.                   String[] emailAddress = strEmail.Split(';');  
      15.                  
      16.   
      17.                   
      18.   
      19.                   // String[] emailAddress=strEmail.Split(new  char[] {','});  
      20.                    
      21.               }  
      22.               foreach (string email in emailAddress)  
      23.               {  
      24.   
      25.                   MailMessage msg = new MailMessage();  
      26.   
      27.   
      28.                   msg.To.Add(email);  
      29.   
      30.   
      31.                   msg.From = new MailAddress("shola007@projectserver01.local");  
      32.   
      33.                   msg.Subject ="My 40th Birthday";  
      34.   
      35.                   msg.Body = description.Text;  
      36.                     
      37.   
      38.                   SmtpClient smtp = new SmtpClient("moss.projectserver01.local");  
      39.                   smtp.Send(msg);  
      40.   
      41.   
      42.               }  
      43.           }  
      44.       }


    Thanks,

    Krunal.

    Thanks,
    Krunal
    Please Mark as answer if it helps.it will help others to find the solution.
  • Re: looping through values in a people editor controls

    07-22-2009, 6:24 AM
    • Member
      5 point Member
    • ghostme
    • Member since 10-02-2007, 11:31 AM
    • Posts 35

    Thanks Krunal,


    I am really grateful for your code, it is now working.

    Regards

Page 1 of 1 (7 items)