SharePoint 2010: Programmatically wokring with Calculated, Lookup and Hyperlink fields

While working on event receivers in SharePoint 2010, I was required to access thelook up fields and calculated fields in from a list. So here is how I accessed the value of both the fields.
SPFieldLookupValue fieldValue = new SPFieldLookupValue(properties.ListItem["ProjectsList"].ToString());
SPFieldCalculated cf = (SPFieldCalculated)properties.ListItem.Fields.GetField("Auslastung");
properties.ListItem["EventHeading"] = fieldValue.LookupValue + ":" + cf.GetFieldValueAsText(properties.ListItem["Auslastung"]);
Where as in case you intent to set value for Hyperlink type field it has it own class that can be used in the following manner.
SPFieldUrlValue teamURL = new SPFieldUrlValue();
teamURL.Description = "View Team Calendar";
teamURL.Url = properties.Web.Url.ToString() + "\\" + item.Url + "?groupID=" + groupID.ToString(); ;
properties.ListItem["ViewTeamCalender"] = teamURL;
As you could see, here I intended to set a querystring in the URL and that worked perfectly as I had a webpart making use of the value in the query string. I will soon mention a little trick to access query string via Webpart. Hope this helps. Cheers

Comments

Popular posts from this blog

SPFx: Develop using SharePoint Framework without Installing all the dependecies.

SharePoint Online: Elevated Permissions....with love

Powershell: Filling up an Existing Excel Sheet with data from SQL Server