开发者

xmlns to sharepoint api object

Is it possible to con开发者_开发问答vert 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\"><my:DisplayName>devadmin</my:DisplayName><my:AccountId>GLINTT\\devadmin</my:AccountId><my:AccountType>User</my:AccountType></my:Person>"

Thanks, David Esteves


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


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;


    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜