예제 #1
0
        private void UpdateSPProfile(string server, string login, byte[] image)
        {
            using (SPSite site = new SPSite(server))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPServiceContext   sc      = SPServiceContext.GetContext(site);
                    UserProfileManager upm     = null;
                    UserProfile        profile = null;

                    try
                    {
                        upm = new UserProfileManager(sc);
                    }
                    catch (Exception e)
                    {
                        string message = "Не вдалося отримати доступ до профілів користувачів. Повідомлення Sharepoint:\r\n" +
                                         e.Message;
                        throw new Exception(message);
                    }

                    try
                    {
                        profile = upm.GetUserProfile(login);
                    }
                    catch (Exception e)
                    {
                        string message = string.Format("Не вдалося отримати доступ к профілю користувача \"{0}\". Повідомлення Sharepoint:\r\n{1}",
                                                       login, e.Message);
                        throw new Exception(message);
                    }

                    if (profile != null)
                    {
                        if (image != null)
                        {
                            SPProfilePhotoUploader imageUploader = new SPProfilePhotoUploader(web);

                            if (imageUploader != null)
                            {
                                imageUploader.UploadPhoto(profile, image);
                                string pictureUrl = String.Format("{0}/{1}/{2}_MThumb.jpg", site.Url,
                                                                  imageUploader.GetSubfolderName(), imageUploader.GetFileNameFromAccount(profile));
                                WriteSPProfileField(ref profile, "PictureUrl", pictureUrl);
                            }
                        }
                        else
                        {
                            if (profile["PictureUrl"].Value != null && profile["PictureUrl"].Value.ToString().Length > 0)
                            {
                                // TODO: Remove image?
                                WriteSPProfileField(ref profile, "PictureUrl", null);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private void UpdateSPProfile(string server, string login, byte[] image)
        {
            using (SPSite site = new SPSite(server))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPServiceContext sc = SPServiceContext.GetContext(site);
                    UserProfileManager upm = null;
                    UserProfile profile = null;

                    try
                    {
                        upm = new UserProfileManager(sc);
                    }
                    catch (Exception e)
                    {
                        string message = "Не вдалося отримати доступ до профілів користувачів. Повідомлення Sharepoint:\r\n" +
                            e.Message;
                        throw new Exception(message);
                    }

                    try
                    {
                        profile = upm.GetUserProfile(login);
                    }
                    catch (Exception e)
                    {
                        string message = string.Format("Не вдалося отримати доступ к профілю користувача \"{0}\". Повідомлення Sharepoint:\r\n{1}",
                            login, e.Message);
                        throw new Exception(message);
                    }

                    if (profile != null)
                    {
                        if (image != null)
                        {
                            SPProfilePhotoUploader imageUploader = new SPProfilePhotoUploader(web);

                            if (imageUploader != null)
                            {
                                imageUploader.UploadPhoto(profile, image);
                                string pictureUrl = String.Format("{0}/{1}/{2}_MThumb.jpg", site.Url,
                                    imageUploader.GetSubfolderName(), imageUploader.GetFileNameFromAccount(profile));
                                WriteSPProfileField(ref profile, "PictureUrl", pictureUrl);
                            }
                        }
                        else
                        {

                            if (profile["PictureUrl"].Value != null && profile["PictureUrl"].Value.ToString().Length > 0)
                            {
                                // TODO: Remove image?
                                WriteSPProfileField(ref profile, "PictureUrl", null);
                            }
                        }
                    }
                }
            }
        }