"Cannot complete this action" when updating a Hyperlink field in a Links list.

The Gods of the sharepoint object model laugh loudly when they see you type this code:

SPListItem link = links.Items.Add();
link["URL"] =
string.Format("http://www.domain.com/sites/sitename/{1}/,{0}", subsite, linkText);
link["OpenInNewWindow"] = "false";
link.Update();

So, what's wrong with it? Very hard to spot this one. Upon inspection of working hyperlink fields that
have been added through the web interface, it's easy to miss that there should be a space after the
comma separating the url and the display text:

//  there is now a space between '...{1}/,' and '{0}'
link["URL"] = string.Format("http://www.domain.com/sites/sitename/{1}/, {0}", subsite, linkText);

Hilarious, not. Scratch up another three hours on "cannot complete this action."

blog comments powered by Disqus

About the author

Irish, PowerShell MVP, .NET/ASP.NET/SharePoint Developer, Budding Architect. Developer. Montrealer. Opinionated. Montreal, Quebec.

Month List

Page List