# Thursday, March 16, 2006

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."

Comments are closed.