Get and Set a SharePoint URL Field Value Programmatically

Get and Set SharePoint Field using C#

In this hint, I will explain how to programmatically Get and Set a SharePoint URL Field Value using C#?


How to Get and Set a SharePoint URL Field Value Programmatically using C#?

In this section, we will show how to get and set SharePoint Hyperlink Field value in SharePoint List using C# (Server Side Object Model).

Get and set SharePoint URL field Value  programmatically

SharePoint set URL field value

Consider, you have a SharePoint List that has a Hyperlink or Picture field and you would like to update and set the SharePoint Hyperlink or Picture Field Value programmatically using C#.

In this case, you should use the below “setURLfieldvalue()” function and providing your List name and field name to can set Hyperlink or Picture Field Value using C#.

C# Code

public void setURLfieldvalue() {
 using(SPSite site = new SPSite(SPContext.Current.Site.Url)) {
  using(SPWeb web = site.OpenWeb()) {
   SPList list = web.Lists["Users"];
   SPListItem item = list.GetItemById(1);
   SPFieldUrlValue urlValue = new SPFieldUrlValue();
   urlValue.Url = "http://www.google.com";
   urlValue.Description = "Google";
   item["FieldName"] = urlValue;
   item.Update();
  }
 }
}

SharePoint get URL field value

In the previous section, we have learned how to set URL field Value programmatically using C#, In this section, we will show how to get SharePoint URL Field Value Using C#.

C# Code

public void GetURLfieldvalue() {
 using(SPSite site = new SPSite(SPContext.Current.Site.Url)) {
  using(SPWeb web = site.OpenWeb()) {
   SPList list = web.Lists["Users"];
   SPListItem item = list.GetItemById(1);
   SPFieldUrlValue urlValue = new SPFieldUrlValue(item["FieldName"].ToString());
   string url = urlValue.Url;
   string description = urlValue.Description;
  }
 }
}

Conclusion

In conclusion, we have learned how to Get and Set a SharePoint URL Field value Programmatically using Server Object Model C#?

Applies To
  • SharePoint 2016.
  • SharePoint 2013.
  • SharePoint 2010.
  • C# SSOM.
You might also like to read
Have a Question?

If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.

1 thought on “Get and Set a SharePoint URL Field Value Programmatically”

  1. Pingback: Get SharePoint Choice Field Value In C# | SPGeeks

Leave a Reply

Scroll to Top