Thursday, June 9, 2011

Generic method to get the SPListItem data from field internal lname or display name

Into one of the method of my code i had to display the list item data, but only those fields/columns that are set by Editor.

Now till that point i only knew that Editor will put column names in property bag as comma delimited but whether he will set internal name or display name of fields, no idea.

So I had to get the fields data by using some method which takes both Internal Name and Display name as parameter.

And here is the solution:

foreach (string field in fields)
details += Server.HtmlDecode(delimiter) +
Convert.ToString(item[item.Fields.GetField(field.Trim()).Id]);

No comments: