I was trying to update a URL field of a task within a custom workflow I was writing and spent a bit more time than I’d have liked trying to get the URL and description to save correctly in the task item being created as part of the CreateTaskWithContentType activity.
Obviously you can’t save a SPFieldUrlValue as an object directly against the ExtendedProperties as it is not a simple type, such as a string or an integer. Nearly every other field provided with SharePoint that contains multiple values is separated by the #; characters. The URL field is different in that it uses the comma as the separator. I knew this and set the extended property to something like:
TaskProperties.ExtendedProperties[guidIdOfField] = "http://somewebaddress,Description";
When the task was created the field displayed http://somewebaddress,Description and not Description as I wanted.
It turns out that I forgot to separate using a comma and a space like:
TaskProperties.ExtendedProperties[guidIdOfField] = "http://somewebaddress, Description";
This gave me the desired result of Description as the display text for the field.
A better solution and one that shouldn’t break if Microsoft ever decide to change how URL fields store their data, is to use the SPFieldUrlValue object to set the property value, as demonstrated below:
SPFieldUrlValue urlValue = new SPFieldUrlValue(); urlValue.Url = "http://someurl.com"; urlValue.Description = "URL Description"; createTaskWithContentType.TaskProperties.ExtendedProperties[guidIdOfField] = urlValue.ToString();
This ensures that the URL is formatted to exactly how SharePoint internally expects it.