0

I am using a people picker control to get all SP users.When i click save button i am adding the users to a group and displaying users in a drop down list.But the users look like i:0#.f|m1010|arun8. I want this in eg: PCname\arun8.I am using a calendar list(event type).

      foreach (string UserSeperated in UsersSeperated)
               {
                         mySite.EnsureUser(UserSeperated);
                         SPUser User = mySite.SiteUsers[UserSeperated];                                            
                         oWeb.AllowUnsafeUpdates = true;
                         oWeb.Groups["Presenters"].AddUser(User);
                         oWeb.AllowUnsafeUpdates = false;
                         presenter = User.LoginName;  
                         presenterName = Environment.MachineName + "\\" + presenter ;
                         DDPresenter.Items.Insert(0, presenterName);                                                       
                }
1

It looks like you're using Forms Bases Authentication, and that would explain why usernames contains i:0#.f|m1010|.

Try splitting the User.LoginName.

mySite.EnsureUser(UserSeperated);
SPUser User = mySite.SiteUsers[UserSeperated];                                            
oWeb.AllowUnsafeUpdates = true;
oWeb.Groups["Presenters"].AddUser(User);
oWeb.AllowUnsafeUpdates = false;
presenter = User.LoginName.Split('|')[2];  
presenterName = Environment.MachineName + "\\" + presenter ;
DDPresenter.Items.Insert(0, presenterName); 
  • Split('i:0#.f|m1010|') is showing too many characters in character literal – anish Sep 4 '13 at 6:59
  • 1
    presenter = User.LoginName.Split('|')[2]; – anish Sep 4 '13 at 7:01
  • @anish Ah, yes that's true. I updated it in my post. – user2536 Sep 4 '13 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.