In this hint, I will explain how to programmatically Get and Set a SharePoint URL Field Value 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).
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();
}
}
}
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
- Get and Set a SharePoint Lookup Field Value Using Server Object Model C#.
- Get and Set a SharePoint User Field Value Using Server Object Model C#.
- Get and Set a SharePoint Multiple Choice Field Value Using Server Object Model C#.
- Get and Set a SharePoint Multiple Lookup Field Value Using Server Object Model C#.
- Retrieve a SharePoint Choice Field Value Using Server Object Model C#.
Have a Question?
If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.
Pingback: Get SharePoint Choice Field Value In C# | SPGeeks