Posts Tagged ‘link’

Updating SharePoint Link type field URLs

Tuesday, December 9th, 2008

Writing URLs to link type fields in SharePoint via code can be accomplished by using the SPFieldUrlValue type (C#):

SPFieldUrlValue redirectUrl = new SPFieldUrlValue();
redirectUrl.Url = "http://theServer/app.aspx";
redirectUrl.Description = " Applications";
data.ListItem["Link Field"] = redirectUrl;
data.Update();

Alternatively and more directly (C#):

SPList list = web.Lists["yourlistname"];
SPListItem item = list.Items[0]; //Get the list item
item["Link Field"] = "http://theServer/app.aspx, Applications"; //the first part contains the URL followed by a comma and space, then the URL description
item.Update();

In SharePoint Designer:
First create a string variable (Build Dynamic String action) that contains the URL and link description:
for example “http://theServer/app.aspx, Applications” (like in the first example above).
Then set the link field value equal to the variable.

For email links use the following syntax:
mailto:email@address, Name of Contact
Again note that there must be a comma and a space between the email address and the contact name.