2010-07-23 39 views
1

是否可以將以下字符串轉換爲Sharepoint API對象,如SPUser或SPUserValueField? (不解析它)xmlns到sharepoint api對象

"<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>" 

謝謝, 大衛埃斯特維斯

回答

0

是的,Microsoft.Office.Workflow.Utility程序集有Contact.ToContacts,它將將Person XML反序列化成Contact個實例。

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

-Oisin

+0

謝謝,那正是我正在尋找的。 – 2010-07-26 17:31:37

+0

是的,大約兩年後我偶然發現了它。隱藏在API中的東西太多了。 – x0n 2010-07-26 21:22:24

0

解決:)

(只是一個例子) 下面的函數從人檢索SPUser:

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

功能更新,檢索SPUser對象,而不是與ACCOUNTID的字符串。無論如何,正確的方法是使用Oisin發佈的函數。 – 2010-07-26 17:33:09