I needed to copy a few profile fields from SharePoint Portal 2003 to Microsoft Office SharePoint Portal 2007 (v12) because some property values didn't come from Active Directory.
ProfileExporter-SpsV2 - Export SharePoint 2003 profile fields
I created this tool to export SharePoint 2003 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-SpsV2.exe http://sps2003
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
ProfileExporter-SpsV2 - Source code
(Note: add Reference C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI\Microsoft.SharePoint.Portal.dll)
using System;
using System.Collections;
using System.Xml;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal.UserProfiles;
namespace ProfileExporter_SpsV2
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
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");
TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new Uri(url)];
PortalContext context = PortalApplication.GetContext(portal);
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;
}
}
}