在删除和恢复配置文件后,如何恢复SharePoint"我的链接"?

Kwi*_*irk 3 sharepoint sharepoint-2007 personalization

我们正在运行SharePoint 2007 SP1,并且从Active Directory导入配置文件(每天运行完整导入).我们遇到了一个问题,即许多用户在Active Directory中无意中被禁用,这导致他们的配置文件从SharePoint中删除.我们重新启用了他们的Active Directory帐户并运行了完整导入以恢复其SharePoint配置文件.但是,他们所有的My Links都丢失了.是否有恢复它们的方法或最佳实践?

Kwi*_*irk 6

我发布了这个因为我无法在任何地方找到问题的答案. Joel Oleson撰写的这篇文章描述了一个与我类似的问题,给了我一个关于去哪里寻找缺失数据的提示.而这篇文章由科里·罗斯告诉我如何编程的链接添加到用户的我的链接.

首先 - 您需要恢复包含My Links数据的数据库的备份.您不希望还原工作数据库,而是希望将其还原到其他位置.存储在SSP数据库中的链接.(您可以通过进入中央管理员 - >共享服务管理员找到数据库的名称,然后打开SSP的菜单,然后单击编辑属性 - 属性页上列出了SSP数据库.)

恢复数据库后,您需要检索链接信息:

  • 拥有该链接的用户的域帐户名,
  • 链接的网址
  • 链接的名称

此查询将为您提供以下信息:

SELECT UPF.NTName, UL.Url, UL.Title
FROM UserLinks UL INNER JOIN UserProfile_full UPF ON UL.recordID = UPF.recordID
INNER JOIN UserPrivacyPolicy UPP ON UL.PolicyId = UPP.id
ORDER BY NTName
Run Code Online (Sandbox Code Playgroud)

(我应该注意,我没有考虑链接设置的组或隐私级别,您可以通过查看UserPrivacyPolicy表中的信息找到该信息)

我将结果复制到Excel并将其保存为.csv文件(逗号分隔列表) - 只是因为我的生产服务器无法访问我恢复数据库的位置.我订购了标题最后的列,因为标题可能包含逗号,这会弄乱我在读数据的方式.(我检查过,其他两个字段不包含逗号 - 在做出这个假设之前,你应该检查一下.)

然后我写了一个小控制台应用程序来导入数据.它需要两个参数:

  • 包含所有链接的文件所在的路径(即c:\ temp\links.csv)
  • 来自My Links的SSP网址丢失了(即https://portal.mydomain.com)

这些是使用的参考:

  • Microsoft.Office.Server(C:\ Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.dll)
  • Microsoft.SharePoint(C:\ Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll)
  • 系统
  • System.Data
  • 的System.Web
  • 的System.Xml

这是代码:

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Web;

namespace UserLinks
{
    class Program
    {
        static void Main(string[] args)
        {
            string _accountName = "", _linkTitle = "", _url = "", _tmp = "", _path = "", _SPSsite = "";

            // Check arguments
            if (args.Length != 2)
            {
                ShowUsage();
                return;
            }

            _path = args[0];
            _SPSsite = args[1];

            using (SPSite _site = new SPSite(_SPSsite))
            {
                ServerContext _context = ServerContext.GetContext(_site);
                UserProfileManager _userProfileManger = new UserProfileManager(_context);

                /* Expecting a comma seperated list with 3 columns:  
                 * AccountName in the format Domain\Account name - I am assuming there are no commas in this field
                 * URL - I am assuming there are no commas in this field
                 * Link Title - link title is last because there may be commas in the title
                */
                TextReader _reader = new StreamReader(_path, System.Text.Encoding.Default);
                while (_reader.Peek() != -1)
                {
                    _tmp = _reader.ReadLine();
                    _accountName = _tmp.Substring(0, _tmp.IndexOf(','));
                    _tmp = _tmp.Replace(_accountName + ",", "");
                    _url = _tmp.Substring(0, _tmp.IndexOf(','));
                    _linkTitle = _tmp.Replace(_url + ",", "");

                    try
                    {
                        UserProfile _currentUser = _userProfileManger.GetUserProfile(_accountName);
                        QuickLinkManager _quickLinkManager = _currentUser.QuickLinks;
                        _quickLinkManager.Create(_linkTitle, _url, QuickLinkGroupType.General, null, Privacy.Private);  //I am assuming that all links have no group assigned to them and they are all private links
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(_accountName);
                        Console.WriteLine(ex);
                    }

                }
                _reader.Close();

            }
        }

        private static void ShowUsage()
        {
            Console.WriteLine("Usage");
            Console.WriteLine("UserLinks [FilePath] [SharePoint URL]");
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

因此解决了问题并且作为附带好处,此程序可用于强制链接显示在用户的"我的链接"列表中.