Odpovědět User profile picture.

  • 22. srpna 2012 9:22
     
      Obsahuje kód

    Hi,

    I am trying to update the user picture using SharePoint object model.the pictures are currently in file server. so i am trying to move that into userphoto library in mysite.

    i am planning to run the below code daily so that the picture urls are updated to all the profiles.

     SPServiceContext context = SPServiceContext.GetContext(site);
                    UserProfileManager myUserProfileManager = new UserProfileManager(context);
    
                    try
                    {
                        foreach (UserProfile aUser in myUserProfileManager)
                        { 
    string newurl = "http://server/user photo/empid.jpg";
                                    aUser[PropertyConstants.PictureUrl].Value = newurl;
                                    aUser.Commit();
    }
    }

    after this i have to run the powershell script which will create the thumbnail picture Update-SPProfilePhotoStore.

    The above command creates the another folder inside the picture library and creates creates 3 thumbnail pictures.

    now  in future when new employee joins, i have the HR upload the picture to this library with employee id.so do i need to run the c# code and powershell script daily to update the url and create the thumbnail. is this the only way?

    Please let me know if the question is not clear.

Všechny reakce

  • 22. srpna 2012 10:04
     
     

    Hi,

    You can see the right code at below location. This worked for us.

    http://burcakcakiroglu.com/?p=2804


    -Kranthi

  • 22. srpna 2012 11:30
     
     

    hi,

    I am not sure what exactly they are trying to do.

    In my case i am able to get the things working for the existing employee.But my problem is when new employee joins do we need to do the same thing which i am doing in the above code? or is there some other way around?

    Thanks,

    Sudan

  • 22. srpna 2012 11:40
    Moderátor
     
     Odpovědět

    Hi,

    >HR upload the picture to this library with employee id.

    In your case, HR will update user pic in library so you have to update same in user profile. You will need to run above code and  Update-SPProfilePhotoStore every time when new picture is added in library.

    I will suggest to create an event handler for that library and this handler will call when you add new pic in library. You can also call powershell command from your code so you don't need to perform any manual operation.

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    • Označen jako odpověď Sudan12 22. srpna 2012 19:36
    •  
  • 22. srpna 2012 19:36
     
     

    Hi Hemendra,

    Thanks for the suggestion, will try it.

    Thanks,

    Sudan