Updating URL field for ExtendedProperties in workflow

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.

This entry was posted in SharePoint, Workflow and tagged , . Bookmark the permalink.

3 Responses to Updating URL field for ExtendedProperties in workflow

  1. Andy Diericks says:

    Thanks very helpful, I’ve tried first to set it up as a simple string but without success.

  2. Rob Smith says:

    Many thanks for this post.

    Found this incredibly frustrating. Never would have occurred me to use this workaround.

  3. Tarcisio says:

    Hi, Thank you!

    I was trying to another way…by cast….but it’s doesn’t work

Leave a Reply to Rob Smith Cancel reply

Your email address will not be published. Required fields are marked *

Solve the maths problem shown below before posting: *