Category Archives: Programming
Remember to allow unsafe updates when you do an SPWeb.EnsureUser
I recently came across this error:
Microsoft.SharePoint.SPException: Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb.
I was using SharePoint object model code, and since I didn’t think I was updating anything, just retrieving data from SharePoint, I did not use SPWeb.AllowUnsafeUpdates = true. That was fine for all the lines in my method except one, which used SPWeb.EnsureUser, which will give you back an SPUser object for a given login name, or create one as necessary, hence the update part. I will say that this was one of the more informative error messages.
How to fix Visual Studio when CTRL F does not work
Use static methods judiciously
XPath designer/debugger
Found a great utility that’s free called SketchPath. I was able to visualize my XPath expressions easily with this tool.
InfoPath or ASP.NET forms?
Having done a ton of InfoPath from simple to very complex, I’m itching to do more ASP.NET forms development. Especially with the issues around SharePoint and item-level security… it’s hard to do enterprise form applications with SharePoint without trespassing the ACL limits. I’ve learned a lot of good practices (e.g., use AD groups, partition content to multiple site collections and content databases). I’m going to follow through on these best practices in my work (learned the hard way), but I can’t help thinking that for those big, complex forms with lots of item-level permissions, perhaps that could be handled better via an ASP.NET form and a database. Yes, it requires a lot more consideration into architecture, as well as a competent .NET developer, but once one or two of these applications have been built, a company has a platform for doing enterprise form apps. They can even display the form app in SharePoint through a Page Viewer web part, so it would be a seamless experience to the user.
Here is an authoritative article on pros and cons of the InfoPath and ASP.NET forms.