#henrik

development and technology stuff

SPListItem - SPFieldLookupValue

If I use the SharePoint object-model to set items my "normal" approach is:

SPListItem item;
item["fieldName"] = "value";

This works as expected until the field in question is a lookup-field. Using the approach mentioned above I always got an exception. The reason for this is, that a lookup values always contain a key and value ==> 1#;Value So the correct code would look like this:

int lookupId;
string lookupValue;
item["fieldName"] = new SPFieldLookupValue(lookupId, lookupValue);

Thanks to Sridhar's Blog.

Filed under  //   Development   SharePoint   Sharepoint Development   c#   object-model  
Posted May 21, 2009

SPSite/SPWeb dispose

When working with the SharePoint object-model there is the issue to correctly dispose SPSite and SPWeb objects. There is a nice blog-post listing best-practice patterns. Today I found a tool which helps to find dispose issues in your code - the tool is called SPDisposeCheck. The tool analyzes libraries and executables and lists dispose issues. It can be nicely integrated into your build process by using the tool with the build events in visual studio.

Filed under  //   Sharepoint Development   moss   object-model