您好,感谢您的阅读。我一直在与网站的Out-Box SharePoint 2010新闻供稿部分合作,我计划将其部署给许多用户。

我正在构建一个控制台应用程序,该应用程序将遍历当前系统中的所有网站,并取消检查“我为每个用户遵循的活动'的活动之一。我已经使用了提供的示例 这个链接 (MSDN)提出以下代码:

Public Class ChangeActivity
'Reference: http://msdn.microsoft.com/en-us/library/ff426883.aspx'


Public Shared Sub ChangeActivityProperties()
    Using siteCol As New SPSite((My.Application.CommandLineArgs(0)))
                Dim context As SPServiceContext = SPServiceContext.GetContext(siteCol)
                Dim profileManager As New UserProfileManager(context)
                Dim profile As UserProfile = profileManager.GetUserProfile("THEDOMAIN\username")
                Dim activityMan As ActivityManager = New ActivityManager(profile, context)

                'Create an instance of a list of ActivityPreferencePerType objects.'
                Dim activityPrefsPerType As New List(Of ActivityPreferencePerType)(activityMan.ActivityTypes.Count)

                'Get each ActivityType stored in ActivityManager, and for testing purposes, set each ActivityType as a true ActivityPreference.'
                For Each activityType As ActivityType In activityMan.ActivityTypes
                    If activityType.ActivityTypeNameLocStringName = "ActivityFeed_DLMembershipChange_Type_Display" Then

                        Dim newPref As New ActivityPreferencePerType()
                        newPref.ActivityType = activityType
                        newPref.IsSet = False
                        activityPrefsPerType.Add(newPref)
                        Console.WriteLine(activityType.ActivityTypeName + " " + activityType.ActivityTypeId.ToString())

                    End If
                Next

                'Set activity preferences for the user.'
                activityMan.ActivityPreferences.SetActivityPreferencesPerType(activityPrefsPerType)

                Console.ReadKey(True)

    End Using
End Sub
End Class

该代码在没有错误的情况下编译和执行,但似乎对用户为其新闻提要订阅的活动没有影响。其他人也有类似的问题吗?如果要认真尝试在SharePoint 2010中实施我的网站,这似乎是一个足够普遍的问题。

感谢您的时间,并提前帮助。

干杯,

菲尔

更新进行一些powershell侦查,看来这可能是我的ActivityManager对象的问题。我如上所述实例化ActivityManager对象,以“ thedomain username”为“用户”。当我在创建对象后检查对象时,似乎将“ CurrentUsername”设置为服务帐户(恰好是我在计算机上登录的帐户)。 MSDN将ActivityManager的当前用户成员描述为:

“获取代表当前用户名称的字符串。”

ActivityManager中的属性似乎也像服务帐户的设置一样配置,而不是“ Thedomain username”用户。

有帮助吗?

解决方案

在ActivityManager组件上使用.NET Reflector,我得出的结论是,Microsoft将这些设置放在除了拥有该帐户的用户之外,没有任何人更改这些设置。在上面的情况下,我试图在登录为农场管理员时通过控制台命令运行代码。因为农场帐户!=应用设置应用的用户帐户,所以Microsoft禁止对设置的修改。

当用户首次登录其序列时,我们可以通过让用户运行此代码来解决此问题。

其他提示

如果将应用程序池所有者添加到拥有用户配置文件服务的组,则也可以解决权限问题。该代码是从应用程序池所有者运行的,但是该人必须是UPS所有者,因为使用活动管理器需要它。只是使用MS产品的另一个好处!

许可以下: CC-BY-SA归因
scroll top