AAron nAAs

All MindsharpBlogs

AAron's SharePoint notepad

My Links

Archives

Blog Stats

My Sites

Copy Profile from MOSS 2007 to MOSS 2007

I needed to copy a few profile fields in SharePoint MOSS 2007 from an old SSP to a new SSP. The Shared Services Provider needed to be rebuilt (as recommended by Microsoft) to fix a problem. We had a few fields that were not in Active Directory, so once the new SSP was ready and synced, the unique values needed to be copied across.

ProfileExporter - Export SharePoint MOSS 2007 profile fields

I created this tool to export profile values and work with the importer (mentioned below). It takes the importer's mapfile.xml and uses the InputField field names and pulls their values into an inputfile.xml file which the importer can also use. Example use:

mapfile.xml (input to execution)

<Mappings>
    <Mapping InputField="AccountName" MOSSField="AccountName" />     <!-- required by import -->
    <Mapping InputField="Title" MOSSField="Title" />
    <Mapping InputField="MyCustomProperty" MOSSField="MyCustomProperty" />
</Mappings>

export command

ProfileExporter http://moss:<SSPport>/ssp/admin

inputfile.xml (result from execution)

<?xml version="1.0"?>
<Inputs>
      <Input>
            <AccountName>DOMAIN\aaron.naas</AccountName>
            <Title>SharePoint'er</Title>
            <MyCustomProperty>supercalifragilisticexpealidocious</MyCustomProperty>
      </Input>
      <Input>
            <AccountName>DOMAIN\someone.else</AccountName>
            <Title>Nobody</Title>
            <MyCustomProperty>blahblah</MyCustomProperty>
      </Input>
</Inputs>

(source code appended to bottom of post)

SharePoint 2007 Shared Services Provider User Profile Importer

There is a nice freely available importer for 2007, but it does have some annoyances. If a user's profile is missing during the import, it stops running (I suggest you move the GetUserProfile call down a few lines into the try block to allow it to continue on error). I also had a problem trying to import values into “date time” fields (see my reported issue).

SharePoint 2007 Shared Services Provider User Profile Importer

Download the most recent source code here.

import command

PI.exe -mapping mapfile.xml -inputs inputfile.xml -url http://moss2007:<SSPport>/ssp/admin

ProfileExporter - Source code

using System;

using System.Collections;

using System.Xml;

using Microsoft.SharePoint;

 

using Microsoft.Office.Server;

using Microsoft.Office.Server.Administration;

using Microsoft.Office.Server.UserProfiles;

 

namespace ProfileExporter

{

    class Program

    {

        [STAThread]

        static void Main(string[] args)

        {

            if (args.Length < 1)

            {

                Console.WriteLine("Usage: {0} <SSPUrl> ", typeof(Program).Assembly.ManifestModule.Name);

                Console.WriteLine("\tSSPUrl - Url of SSP. Example: http://hostname:20072/ssp/admin");

                return;

            }

            string url = args[0];

 

            XmlTextWriter writer = null;

 

            Hashtable desiredKeys = ReadProfileKeys("mapfile.xml");

 

            try

            {

                writer = new XmlTextWriter("inputfile.xml", null);

                writer.Formatting = Formatting.Indented;

                writer.Indentation = 6;

                writer.Namespaces = false;

                writer.WriteStartDocument();

                writer.WriteStartElement("Inputs");

 

                using (SPSite site = new SPSite(url))

                {

                    ServerContext context = ServerContext.GetContext(site);

                    UserProfileManager profileManager = new UserProfileManager(context);

 

                    string key;

                    string val;

                    foreach (UserProfile profile in profileManager)

                    {

                        writer.WriteStartElement("Input");

 

                        IDictionaryEnumerator e = profile.GetEnumerator();

                        while (e.MoveNext())

                        {

                            key = (string)e.Key;

                            if (desiredKeys.ContainsKey(key))

                            {

                                val = (profile[key] != null) ? profile[key].ToString() : null;

                                writer.WriteStartElement(key);

                                writer.WriteString(val);

                                writer.WriteEndElement();

                            }

                        }

                        writer.WriteEndElement();

                    }

                    writer.WriteEndElement();

                    writer.WriteEndDocument();

                }

            }

            catch (Exception ex)

            {

                Console.Error.WriteLine("Error: Caught " + ex.ToString());

            }

            finally

            {

                if (writer != null)

                {

                    writer.Flush();

                    writer.Close();

                }

            }

        }

 

        static Hashtable ReadProfileKeys(string fn)

        {

            Hashtable hash = new Hashtable();

            XmlTextReader reader = new XmlTextReader(fn);

            string inputField;

            while (reader.Read())

            {

                if (reader.NodeType == XmlNodeType.Element)

                {

                    if (reader.LocalName.Equals("Mapping"))

                    {

                        inputField = reader.GetAttribute("InputField");

                        hash[inputField] = 1;

                    }

                }

            }

            return hash;

        }

    }

}

 

posted on Wednesday, March 12, 2008 11:05 PM

Feedback

No comments posted yet.
Title  
Name  
Url
CAPTCHA
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments