以下代码使用SP Server OM,我想知道如何使用客户端OM检索任务扩展属性。
list = web.Lists["Tasks"];
SPQuery tasksQuery = new SPQuery();
tasksQuery.Query = @"<Where>
<Or>
<Eq>
<FieldRef Name='Status' /><Value Type='Choice'>In Progress</Value>
</Eq>
<Eq>
<FieldRef Name='Status' /><Value Type='Choice'>Not Started</Value>
</Eq>
</Or>
</Where>";
SPListItemCollection tasksListItemCollection =list.GetItems(tasksQuery);
foreach (SPListItem item in tasksListItemCollection)
{
Hashtable extendedProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(item);
}
提前谢谢。
答案 0 :(得分:2)
CSOM
中没有SPWorkflowTask.GetExtendedPropertiesAsHashtable method的模拟,但它可以实现(反射器来拯救)。
/// <summary>
/// Gets a hash table that represents the task’s extended properties collection
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
public static Hashtable GetExtendedPropertiesAsHashtable(ListItem task)
{
if (task == null)
{
throw new ArgumentNullException();
}
Hashtable properties = new Hashtable();
string extProperties = (string)task["ExtendedProperties"];
if (!string.IsNullOrEmpty(extProperties))
{
var reader = new XmlTextReader(new StringReader("<Root " + extProperties + " />"))
{
WhitespaceHandling = WhitespaceHandling.Significant
};
reader.MoveToContent();
if (!reader.HasAttributes)
{
return properties;
}
while (reader.MoveToNextAttribute())
{
string propName = reader.Name.Substring(4);
properties[propName] = reader.Value;
}
}
return properties;
}