DCSIMG
How to deal with URL fields in SharePoint Lists programmatically - itaysk

How to deal with URL fields in SharePoint Lists programmatically

Posted Wednesday, October 24, 2007 4:17 PM by Itay Shakury

What seems to be a simple task has very little examples on the web.

This is one quick way:

//Assuming You have an SPWeb object called "web"
SPList
list = web.Lists["YourList"];  //Get a list
SPListItem item = list.Items[0]; //Get an item
item["Link Field"] = "http://blogs.microsoft.co.il/blogs/itaysk, itaysk"; //equivalent to <a href="http://blogs.microsoft.co.il/blogs/itaysk" mce_href="http://blogs.microsoft.co.il/blogs/itaysk"> itaysk </a>
item.Update();

What do we learn? That the URL is stored as a string that contains both the URL it's display text, seperated by a comma.

 

תגים:,

Comments

# re: How to deal with URL fields in SharePoint Lists programmatically

Thursday, October 25, 2007 3:19 AM by Ishai Sagi (SharePoint MVP)

This is not best practice. See code sample below:

SPList list = web.Lists["Links"];

SPListItem newLink = list.Items.Add();

SPFieldUrlValue value = new SPFieldUrlValue();

value.Description = "test";

value.Url = "www.microsoft.com/sharepoint";

newLink["URL"] = value;

newLink.Update();

# Links (10/25/2007) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

Friday, October 26, 2007 2:43 AM by Links (10/25/2007) « Steve Pietrek’s SharePoint Stuff

Pingback from  Links (10/25/2007) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

# re: How to deal with URL fields in SharePoint Lists programmatically

Monday, October 06, 2008 6:03 PM by Glynn Cater

Was spinning around all over trying to find this,THANKS!!

# re: How to deal with URL fields in SharePoint Lists programmatically

Tuesday, February 02, 2010 9:36 PM by Mat

Very useful post!

Mat

www.noramsoft.com

# re: How to deal with URL fields in SharePoint Lists programmatically

Monday, February 15, 2010 3:09 AM by Francis Chartier

Very useful post!

Francis Chartier

SharePoint Expert

http://noramsoft.com

# re: How to deal with URL fields in SharePoint Lists programmatically

Wednesday, March 03, 2010 11:16 PM by Alex

Okay. this may be a stupid question but I'm trying to create a cusom action which navigates to a sharepoint url.  I want to insert a field value into the url.   So for example I will be pointing to the URL: sharepointsiet/.../EditForm.aspx[AND HERE IS WHERE I WANT TO INSERT THE FIELD VALUE FROM ANOTHER LIST]

Any ideas?  

# re: How to deal with URL fields in SharePoint Lists programmatically

Tuesday, August 24, 2010 4:08 PM by monika

very very useful!

# re: How to deal with URL fields in SharePoint Lists programmatically

Wednesday, January 19, 2011 10:14 PM by Srikanth

Very informative. Thank you so much.

# re: How to deal with URL fields in SharePoint Lists programmatically

Sunday, September 25, 2011 5:56 PM by keyur

thanks a lot...

# re: How to deal with URL fields in SharePoint Lists programmatically

Thursday, January 05, 2012 9:35 AM by kshitij

when I use SPFieldUrlValue I am not getting the Link text I am getting following output :

pni6w1162/.../Insight XT Documents/PRT-00001/PRT-00001_AA, PRT-00001_AA

where I expect "PRT-00001_AA" should be displayed & when user clicks on "PRT-00001_AA" it should redirect to corresponding URL.

Any help ?

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: