views:

24

answers:

2

Is it possible to convert the following string to a Sharepoint API object like SPUser or SPUserValueField? (without parsing it)

"<my:Person xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD\"&gt;&lt;my:DisplayName&gt;devadmin&lt;/my:DisplayName&gt;&lt;my:AccountId&gt;GLINTT\\devadmin&lt;/my:AccountId&gt;&lt;my:AccountType&gt;User&lt;/my:AccountType&gt;&lt;/my:Person&gt;"

Thanks, David Esteves

A: 

Solved :)

(Just an example) The following function retrieves the SPUser from person:

protected SPUser GetSPUserFromExtendedPropertiesDelegateTo(string xmnls_node)
    {

        StringBuilder oBuilder = new StringBuilder();
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter(oBuilder);
        System.Xml.XmlTextWriter oXmlWriter = new System.Xml.XmlTextWriter(oStringWriter);
        oXmlWriter.Formatting = System.Xml.Formatting.Indented;

        byte[] byteArray = Encoding.ASCII.GetBytes(xmnls_node);
        MemoryStream stream = new MemoryStream(byteArray);
        System.IO.Stream s = (Stream)stream;

        System.IO.StreamReader _xmlFile = new System.IO.StreamReader(s);

        string _content = _xmlFile.ReadToEnd();
        System.Xml.XmlDocument _doc = new System.Xml.XmlDocument();
        _doc.LoadXml(_content);

        System.Xml.XPath.XPathNavigator navigator = _doc.CreateNavigator();
        System.Xml.XmlNamespaceManager manager = new System.Xml.XmlNamespaceManager(navigator.NameTable);

        manager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD");

        System.Xml.XmlNode _node = _doc.SelectSingleNode("/my:Person/my:AccountId", manager);

        if (_node != null)
        {

           return this.workflowProperties.Web.EnsureUser(_node.InnerText.ToString());

        }

        return null;


    }
David Esteves
Function updated to retrieve a SPUser object instead of a string with the AccountId. Anyway the correct way to do this is using the function Oisin posted.
David Esteves
A: 

Yes, the Microsoft.Office.Workflow.Utility assembly has Contact.ToContacts which will deserialize Person XML into an array of Contact instances.

http://msdn.microsoft.com/en-us/library/ms553588

-Oisin

x0n
Thanks, that was exactly what i was looking for.
David Esteves
Yeah, I stumbled upon it after about two years. So much stuff hidden in the APIs.
x0n