Frage

The code below uses SP Server OM and I would like to know how to retrieve task extended properties using the Client 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);
}

Thank you in advance.

War es hilfreich?

Lösung

there is no an analog for SPWorkflowTask.GetExtendedPropertiesAsHashtable method in CSOM, but it could be implemented (Reflector to the rescue).

How to gets a hash table that represents the task’s extended properties collection via SharePoint Managed CSOM

    /// <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;
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top