When you are developing a custom ECMA 2 based Connector for FIM, you can choose between different ConfigParameterDefinitions to use in the Connectivity, Global, Partition and Run Step ConfigParameterPage. One of them is the CreateFileParameter, which allows you to select (browse for) a file and then stores the content of that file as a Base64 string. You can find a list of all available methods here http://msdn.microsoft.com/en-us/library/windows/desktop/hh858152(v=vs.100).aspx.
And here’s an example:
switch (page)
{
caseConfigParameterPage.Connectivity:
configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("Text"));
configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter("User", ""));
configParametersDefinitions.Add(ConfigParameterDefinition.CreateEncryptedStringParameter("Password", ""));
configParametersDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter());
configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("Text"));
configParametersDefinitions.Add(ConfigParameterDefinition.CreateFileParameter("Attributes"));
break;
}
Now, the question is: how can you access the content of the previously selected file? I spent some time to find a working solution, as the way how the content is encoded with Base64 is not described (at least, I haven’t found it on MSDN or TechNet).
In my case, I have a XML file, which I have to use as part of the GetSchema() method. Accessing the Value property returns the Base64 string:
configParameters["Attributes"].Value;
Therefore, you have to decode it. However, there is one important thing you have to consider: the Byte Order Mark (BOM). Without dealing with the BOM, parsing the decoded string as XML will fail with a “Data at the root level is invalid. Line 1, position 1.” exception. Fortunately, there is a simple solution to get rid of the BOM:
String.Trim().Trim(newchar[] { '\uFEFF' });
After this step, you are able to successfully parse the decoded string and continue to work with the XML, for example by using the XElement class:
var pAttributes = from p inXElement.Parse(decodedString).Elements("Attribute")
select p;