About      |       Articles      |      Services      |      Software      |      Contact

Latest Free SharePoint Software

ARB Security Solutions regularly releases free SharePoint software, including WebParts, Client Applications, Framework Extensions, and other Miscellaneous Components.
The most recent freeware is:

Title: Simple SharePoint Rollup WebPart
Date Published: 10/22/2009

Previous Two Free WebPart Releases:

SecureCenter For SharePoint

By SharePoint security integrators, for SharePoint security integrators.

SharePoint Security Assurance Program™

For externally facing SharePoint deployments, security is an acutely important deployment concern. Learn how through daily security scanning, you can ensure external business users and partners that they can collaborate in confidence!

Security Assurance WebPart:



Getting a SharePoint Field Value In C#

Someone asked me this morning when doing a code review of my code how I got a field value. They were not looking very closely. Here is how I do it, although there are 50,000 other ways of doing it.

This is my getFieldValue helper method, that will be called at other instance points throughout the code.

C#:
  1. public static string getFieldValue(SPListItem listItem, string fieldName)
  2. {
  3. string text = string.Empty;
  4. if (fieldName == string.Empty)
  5. {
  6. return text;
  7. }
  8. try
  9. {
  10. object myObj = listItem[fieldName];
  11. return ((myObj != null) ? myObj.ToString() : string.Empty);
  12. }
  13. catch
  14. {
  15. return string.Empty;
  16. }
  17. }

Once the helper method is defined, then it can be consumed in something like a foreach loop to return SharePoint list items based on conditions. If the condition is not met, it will return null.

C#:
  1. private SPListItem getItemText(SPListItemCollection spItems, string text)
  2. {
  3. foreach (SPListItem item in spItems)
  4. {
  5. if (getFieldValue(item, this.myList.myColumn) == text)
  6. {
  7. return item;
  8. }
  9. }
  10. return null;
  11. }

  • Share/Bookmark

1 Comment »

  1. Very nice method and a good coding practice. Nice work.

    Comment by John — April 9, 2009 @ 4:27 am

RSS feed for comments on this post. TrackBack URL

Leave a comment