Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Uploading images to Mysite "User Photos" picture library

$
0
0

Hi,

My requirement is,

we have all images of employees stored in a center network location http://picture.abcd.net

we created a timer job which runs every weeek and change the picture URL property and it was working fine using the below code

 public override void Execute(Guid contentDbId)
        {
            // gets the webapplication name which was set when the feature was activated and the job created.
            SPWebApplication webApp = this.Parent as SPWebApplication;
            if (webApp.Sites.Count > 0)
            {
                using (SPSite site = new SPSite(webApp.Sites[0].ID))
                {
                    try
                    {
                        // Eventhough running with Elevated Privileges the user running this must have "Manage User Profiles" permission!
                        SPSecurity.RunWithElevatedPrivileges(delegate
                        {
                            {
                                SPServiceContext context = SPServiceContext.GetContext(site);
                                UserProfileManager mngr = new UserProfileManager(context);

                                // loops through all the available user profiles 
                                foreach (UserProfile profile in mngr)
                                {
                                    try
                                    {
                                        string strLoginName = profile["AccountName"].Value == null ? string.Empty : profile["AccountName"].Value.ToString();
                                        if (strLoginName != string.Empty)
                                        {
                                            string imageName = strLoginName.Substring(strLoginName.LastIndexOf("\\") + 1);
                                            string imageUrlTemplate = "http://pictures.abcd.net/employees/{0}.jpg";

                                            // users with "secret" pictures will have an "x" at the end of the imageName. These images will not be displayed here as well.
                                            profile["PictureURL"].Value = string.Format(imageUrlTemplate, imageName);
                                            profile.Commit();
                                            Microsoft.Office.Server.Diagnostics.PortalLog.LogString("User profile is updated for the user " + strLoginName + " ");
                                        }
                                        else
                                        {
                                            Microsoft.Office.Server.Diagnostics.PortalLog.LogString("MySite Img. Sync, Failed to sync, SPUser or UserProfile is null");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Microsoft.Office.Server.Diagnostics.PortalLog.LogString("MySite Img. Sync, Exception: {0} ::: {1}", ex.Message, ex.StackTrace);
                                    }
                                }
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        Microsoft.Office.Server.Diagnostics.PortalLog.LogString("MySite Img. Sync, Exception: {0} ::: {1}", ex.Message, ex.StackTrace);
                    }
                }
            }
        }
    }
}

the problem here is since the images are not stored in User photos library, there are no 3 images with different dimensions are created and hence we get long and stretched images. so we now decided to get the photos from common location and upload to user photos.

what is the best way to do it and how to proceed?


Aruna


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>