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

Alt + W + R
Window > Reset Window Layout
devenv /resetsettings
devenv /setup

Use static methods judiciously

Using static methods can make bug finding harder and exhibit unwanted behavior.  Make sure you really want to use static methods; otherwise, just use regular class methods.  Using static methods requires considering threads, locks, and so forth.

XPath designer/debugger

Found a great utility that’s free called SketchPath.  I was able to visualize my XPath expressions easily with this tool.

Open-source, online XML formatter

Check out CoreFiling’s XML Pretty Printer.

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.

Visual Studio shortcut Ctrl Shift F

I just realized I’d been missing out on a simple yet powerful Visual Studio feature.  If you want to search across files, without having to open up the files, try pressing Ctrl Shift F to Find in Files, or Ctrl Shift H to Replace in Files. See this blog entry for a visual walkthrough.  Visual Studio 2008 gives you search results with the matching text displayed in the Find Results pane at the bottom of the window.

Here’s a VS2008 add-in for finding and replacing using regular expressions, or just use the built-in syntax.

Javascript beautifier

Scrum software project management methodology

Looks interesting: http://www.scrumforteamsystem.com

HTML Validator

For those folks wanting to keep their stuff valid: http://validator.w3.org/.
Follow

Get every new post delivered to your Inbox.