Friday, March 12, 2010

Stupid things in SharePoint 2007 API

For future reference:
  • ItemDeleted event receiver has no information whatsoever on the item that was deleted (quite useful then!)
  • SPWeb.GetFile(string) returns a SPFile object without the correct data (namely Exists and Length properties); using SPWeb.GetFileOrFolderObject(string) on the other hand, after instantiation, does return a valid and correct SPFile object
  • Also on the previous topic, you should always use the web where your file is! Using RootWeb may or may not work well (I have experienced this!). In my case, I was using RootWeb.GetFileOrFolder() / RootWeb.GetFile() and then file.OpenBinary() would return as exception of File Not Found. Using FileWeb.GetFileOrFolder() worked perfectly! As a confirmation of the strange behaviour, in an external console app, RootWeb.GetFileOrFolder() was working!
  • Event Handlers and Timer Jobs do not have request/context objects, that can sometimes be needed so that API methods work correctly and return what you expect (see this post)

(updated everytime I find "funny" things)

No comments:

Post a Comment