code_junkie

Show icon depending on page property

Nov 14th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. SPList list = SPContext.Current.Web.Lists["my list name"];
  2. SPListItem item = list.items.GetItemById(ItemId);
  3.  
  4. //the following 2 lines are not strictly necessary
  5. //but since you explicitly mentioned this is related to ContentTypes
  6. //this is how you can ensure the item you retrieved is of the apprpriate type
  7. SPContentTypeId myContentTypeId = GetContentTypeId();
  8. if (list.ContentTypes.BestMatch(myContentTypeId).Equals(item.ContentType.Id))
  9. {
  10. string value = item["interesting field name"].ToString();
  11. //if the value is of interest, do your thing
  12. }
  13.  
  14. var item = SPContext.Current.File.Item; //returns the SPListItem for the current context
  15. var myField = item["SomeFieldName"]; //this will throw a NullReferenceException if there is no data for the field yet though
  16. Response.Write(myField.ToString());
Add Comment
Please, Sign In to add comment