SharePoint Applied: 10 Things You Wish They Had Told You—Part 2

ave you heard the latest buzz around town? SharePoint is a platform! I think this news caught even Microsoft by surprise. I say that because SharePoint is still grouped under the “server” category and seems to get more IT Pro treatment than developer treatment. The fact is, though, that there is a burgeoning SharePoint developer community, and Microsoft is making significant strides and investments in improving the developer story around SharePoint.

As a developer, you are probably someone who is not afraid of using Visual Studio to cut and prune SharePoint to suit your specific needs. You can do that because SharePoint 2007 is built on ASP.NET 2.0, and it’s significantly customizable.

While SharePoint for ASP.NET 2.0 developers is a huge topic, this article presents five specific topics that can make your SharePoint development life easier.

1. Use Community Tools
To a great extent, the .NET developer community has embraced non-Microsoft, and even open-source tools, to improve their development experience. However, the key difference is that even without using community developer tools, the plain vanilla .NET developer can get by with the tools that Microsoft ships. I love Visual Studio, but for SharePoint specifically, I wish there was an easy way to craft solutions and feature projects. VSeWSS (Visual Studio extensions for Windows SharePoint Services) is available, but it seems a bit behind what the community already has to offer. I am quite certain that developer tool support from Microsoft will improve, but what if you need to deliver a project today?

In the SharePoint world, it is much more acceptable, and frankly deemed an implicit standard to use certain community tools in your development. Specifically, you should to check out the following tools:

  1. CKS: This Community Kit for SharePoint combines several SharePoint projects that solve some key scenarios. Of course, nothing stops you from “borrowing” ideas.
  2. WSPBuilder: This project eliminates the need to craft and maintain the cryptic .ddf files you would usually use to create .wsp solution packages. WSPBuilder iterates through your project structure and creates a .wsp file for you.
  3. STSDEV: This utility lets you create Visual Studio projects to support the feature set you are trying to add to SharePoint.

You can explore some other useful tools as well.

2. Enable Debugging
Debugging is as integral to writing code as tequila is to Mexico. A SharePoint developer’s machine must have SharePoint installed locally, along with Visual Studio and other necessary development tools. And installing SharePoint locally means grabbing it off your MSDN subscription or similar location and installing it in a typical configuration?one that was never meant for debugging. So, when you run into an error in your custom code, SharePoint will simply say “Unexpected Error Occurred.” At that point, depending on your logging settings, it will either log the error to a flat file, not create a log, or create a shorter log.

That is actually a good thing, because you don’t want to expose the gory details of your error (which could possibly contain security-sensitive details) to a remote client over a browser.

But when it comes to debugging, logging to a flat file is not such a good thing, because you want to hit breakpoints and see real error messages instead of seeing “Something bad happened.”

But it’s a relatively easy problem to fix. The following simple alterations to the web.config file will turn your SharePoint install into a debugger-friendly environment:

  1. Change the [email protected] attribute to “true.”
  2. Change the [email protected] attribute to “true”
  3. Change the [email protected] attribute to “Off.”

That’s it. Now when you attach your debugger to the SharePoint w3wp.exe process, it will stop at your breakpoints. Also, instead of seeing “Unexpected Error Occurred,” you will now see a full stack trace and error messages.

Editor’s Note: This article was first published in the September/October 2008 issue of CoDe Magazine, and is reprinted here by permission.

3. Reverse-Engineering SharePoint
“Invention is the art of hiding the source of your inspiration.”

When you see something interesting happen on a SharePoint web page, you may wonder how you could replicate that feature in your own sites. You could start poring through the documentation, ask your friends how to do it, or delegate it to your staff. But perhaps the best option is to cheat by peeking into SharePoint to find out how they did it!

I’d encourage you to cheat, guilt free, by using the following two methods:

  1. Peek into the SharePoint 12 folder, and look in the TemplatesFeatures folder and see how certain features are written.
  2. When authoring a custom feature targeting list definitions, content types, or views, if you’re struggling with the specific CAML syntax, create the list definition manually, and point your browser to the URL http://yoursiteurl/_vti_bin/owssvr.dll?Cmd=ExportList&List={YourListGUID}.

This second approach isn’t perfect. Sometimes the CAML it produces may not validate with the schema, and the CAML structure it produces may not be production ready. But it serves as a perfectly good starting point to copy and paste pieces out of the generated XML, so you don’t have to start at zero.

4. Fix that Annoying Web Part
There was a time when a bunch of Coke-bottle-glasses-wearing scientists pored over punch cards for hours before they dared put them into a computer. But computers are so much cheaper now that the standard development method has turned into:

  1. Write code.
  2. Throw at computer.
  3. See if it works.
  4. If it doesn’t work, debug and fix on the fly. Go to #2.
  5. If it works, go home and play Tetris.

The problem is that a developer may sometimes throw in a Web Part that totally brings down the hosting page to such an extent that the page won’t even run; you can’t even see the “Edit” menu to remove the offending Web Part.

Luckily, there is a back door that lets you remove such Web Parts to fix the page. Simply go to the URL http:///_layouts/spcontnt.aspx?&url=. That page presents you with a menu to clean out these Web Parts from both shared and personal views.

5. Avoiding IISRESET
A fair criticism of SharePoint is how much it likes to make you run IISReset whenever you deploy new functionality. Now, in the real world it shouldn’t matter much, because you can always schedule code deployments at the end of the day, and because your production web farm probably consists of more than one web server?you can update one while the others are running.

But in development, IISReset can get annoying. Every time you hit IISReset, you lose five seconds of your life. By the time you are 70, this will have added up to a few days lost.

A much quicker way is to recycle only the application pool instead of issuing an IISReset. To do that, you can use the following command:

   cscript c:windowssystem32iisapp.vbs      /a "[App_Pool_Name]" /r

A related issue is that every time you recycle either the application pool or issue an IISReset, the next request to SharePoint is extremely slow. That occurs because ASP.NET recompiles the web application. I like to include Spence Harbar’s application recycle utility in my SharePoint virtual machines. I can use this tool to warm up my SharePoint URLs and precompile them, so when a user accesses them, they appear responsive and quick.

SharePoint for developers is a huge topic. There is plenty for a developer to learn?and do?in a SharePoint project. This article discussed only a few of the relatively important tips you might need.

Happy developing!

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: