MOSS User Profile(三):查看用户配置文件修改历史

MOSS User Profile(三):查看用户配置文件修改历史

前面介绍过了用户配置文件的获取和修改,在共享服务管理中心中我没有找到地方来查看指定用户的配置文件的修改历史,只在参考的书中阅读到了阅读到了用对象模型来查看以往修改的记录的方法。

在代码实验中只实验出了查看到添加的属性字段,但是对于字段的值的修改并没有被记录在其中,看来这个只能记录字段的添加删除等操作,对于属性字段值的修改并不能被记录下来。

下面把代码贴出来,来源于参考书中。

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using System.Web;

using Microsoft.Office.Server;

using Microsoft.Office.Server.Administration;

using Microsoft.Office.Server.UserProfiles;

 

namespace ConsoleApplication4

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                using (SPSite site = new SPSite("http://mossweb:1111/sites/Publish"))

                {

                    ServerContext context = ServerContext.GetContext(site);

                    UserProfileManager profileManager = new UserProfileManager(context);

                    // 获取两日之内的变化

                    DateTime startDate = DateTime.UtcNow.Subtract(TimeSpan.FromDays(2));

                    UserProfileChangeQuery changeQuery = new UserProfileChangeQuery(false, true);

                    UserProfileChangeToken changeToken = new UserProfileChangeToken(startDate);

                    changeQuery.ChangeTokenStart = changeToken;

                    changeQuery.Anniversary = true;

                    changeQuery.SingleValueProperty = true;

                    changeQuery.MultiValueProperty = true;

                    changeQuery.DistributionListMembership = true;

                    changeQuery.SiteMembership = true;

                    UserProfile user1 = profileManager.GetUserProfile(@"eoffice\user1");

                    UserProfileChangeCollection changes = user1.GetChanges(changeQuery);

                    foreach (UserProfileChange change in changes)

                    {

                        Console.WriteLine(change.EventTime.ToString());

                        if (change is UserProfilePropertyValueChange)

                        {

                            UserProfilePropertyValueChange propertyChange = (UserProfilePropertyValueChange)change;

                            Console.WriteLine("Property {0} - {1}", propertyChange.ProfileProperty.Name, propertyChange.ChangeType.ToString());

                        }

                        else if (change is UserProfileMembershipChange)

                        {

                            UserProfileMembershipChange membershipChange = (UserProfileMembershipChange)change;

                            Console.WriteLine("Membership {0} - {1}", membershipChange.MemberGroup.DisplayName, membershipChange.ChangeType.ToString());

                        }

                    }

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            Console.ReadLine();

        }

    }

}

其中代码来源于参考资料。
    参考资料:
Sams Microsoft SharePoint 2007 Development Unleashed

你可能感兴趣的:(profile)