I have a Task list, with some custom fields. One of the fields is a hyperlink field which contains a link to a document set that is related to the task. The task is created via the server object model and the metadata is populated in a standard way.
SPListItem newTask = taskList.Items.Add(); SPFieldUrlValue link = new SPFieldUrlValue(); link.Url = docSetURL; link.Description = docSetName; newTask["RelatedLink"] = link; newTask.Update();
When the the task is created, the URL of the hyperlink field doesn't appear to be URL encoded. It is displayed in the edit item modal as
http://mysite/mylib/firstName lastName (12345)
The document sets I link to undergo name updates (which changes the underlying folder name). When the name of the document set is updated, the hyperlink field's URL automatically changes to reflect the new document set URL. This is something SharePoint is doing behind the scenes, not custom logic. This rename encodes the URL, so I am left with
I need this URL to be saved in non-encoded form. I'd love to explain the reasons, but it would cause undue mental hardship to all reading this question. When I try to update the field with the non-encoded version of URL the change doesn't stick, it remains encoded.
var newDocSetHyperlinkField = new SPFieldUrlValue(); newDocSetHyperlinkField.Url = @"http://mysite/mylib/firstName lastName (12345)"; newDocSetHyperlinkField.Description = "Doc Set Name"; task["RelatedLink"] = newDocSetHyperlinkField; task.Update()
I've tested updating the task with PowerShell and it saves the non-encoded URL as expected. Why I am unable to update this field with a non-encoded URL using server object model?