Reformatting Code in Visual Studio

This is one of those things that I can never find — I know it’s there somewhere, but it isn’t where I expect it.  Formatting your code ensures standardized usage of indentations and spaces. It also adds and removes lines near the brace characters that delimit code blocks.  This is especially useful if you find a great code snippet on the Web, paste it into your code, and then it looks all higgledy-piggledy.

To reformat your code, go to the Edit menu, Advanced, and choose either Format Document (Ctrl-E, D) or Format Selection (Ctrl-E, F).  The screen shot below is from Visual Studio 2008, but the functionality is basically the same in previous versions.  There are quite a few other useful text formatting options there as well.

New Picture 

Technorati Tags: ,

SharePoint !NEW Item Icon

It’s a simple little thing to put into your DVWP, but by adding this little snippet of XSL:

<xsl:if test="ddwrt:IfNew(string(@Created))">
    <IMG SRC="/_layouts/1033/images/new.gif" alt="New" />

you can automagically get the little New! Icon icon we’re all so used to seeing if an item has been created within a fixed set of time.  The ddwrt:IfNew function simply tests to see if the date you pass it has occurred since the days-to-show-new-icon property value on your server.  Don’t forget that you can pass a date in other than Created should you want to test something else.  If you are doing this in a DVWP, of course, you can also use an icon which is different than /_layouts/1033/images/new.gif.

By default the days-to-show-new-icon property is set to 2 days, but you can change this property with STSADM:

stsadm.exe -o setproperty -pn days-to-show-new-icon -pv [number_of_days] -url [servername]

If you’d rather not see the icon at all, then set the property to 0.

SharePoint with SQL 2000 vs. SQL 2005: CAML Strictness

I’m working at a client that is developing a highly complex application which is using SharePoint to store some of its content.  The application is written in C# and contains a lot of CAML to go grab content from SharePoint, of course.

We realized the other day that while the developers are working in an environment with SQL 2005, the QA, UAT, and PROD environments are running SQL 2000.  Yes, we should have known this all along, and no, it isn’t very smart.  But let’s put those issues aside. (NEVER allow your environments to get out of synch.  If you do, you aren’t really testing appropriately.)

We had pages failing in the SQL 2000-based environments which worked just fine with SQL 2005.  We narrowed it down to a small section of code which contained CAML to get items from a list:

query.Query = String.Format("<Where><And><Eq><FieldRef Name=’Originator’ /><Value Type=’Text’>EM402357</Value></Eq><Eq><FieldRef Name=’IsDraft’/><Value Type=’Text’>True</Value></Eq></And></Where><OrderBy><FieldRef Name=’DateSaved’ Ascending=’TRUE’ /></OrderBy>");

The test on IsDraft (we also won’t discuss here why the developers aren’t using the built in SharePoint document status concepts) was treating it as a text field, when in fact it was a Yes/No column, or Boolean. Making the simple change in the CAML below solved the problem:

query.Query = String.Format("<Where><And><Eq><FieldRef Name=’Originator’ /><Value Type=’Text’>EM402357</Value></Eq><Eq><FieldRef Name=’IsDraft’/><Value Type=’Boolean’>1</Value></Eq></And></Where><OrderBy><FieldRef Name=’DateSaved’ Ascending=’TRUE’ /></OrderBy>");

The developers were caught by the fact that SQL 2005 is more lenient in how it allows you to specify a value for a Boolean.  In general, write your code, in this case CAML, to the strictest rule and you will be in a much better spot.

SharePoint List Column Naming Best Practice

Try to use English column names (like "Finding Filed By" rather than "FindingBy").  It’ll make your UI nicer to look at.  Also beware of the fact (you’ve no doubt noticed this) that there are actually two names for each column, the display name and the internal name.

For instance, if you create a column called "Finding Filed By", the internal name is "Finding_x0020_Filed_x0020_By".  There is a 32 character cutoff, including the "_x0020_"s. If you rename the column to "FindingBy", the internal name is still "Finding_x0020_Filed_x0020_By".

What I usually do is fiddle while I’m getting things right and then delete the columns that have internal names that are far off from their display names and then add them back so that things are consistent.

Technorati Tags: ,

Interesting Article on SharePoint at Computerworld

There’s an interesting article on SharePoint over at the Computerworld Web site:SharePoint challenges IT as the Excel, Access of the day.

The most interesting part to me is the is the unflattering comparison between the evolution of SharePoint and Lotus Notes usage in the enterprise: "Departmental users used those tools to build applications that collect and manage data because they couldn’t quickly get the projects onto IT’s development schedule."  Yes, that is the basic point, isn’t it?

As technologies have evolved into true "end-user computing tools", IT just hasn’t kept up.  Complex development lifecycles aren’t well-suited to small application programming projects.   Those nasty users are just out there trying to get their work done, and if the IT Department won’t help, they will find a way to work around it.  It doesn’t matter what tool you talk about, it can happen this way.

Do those end users always architect good solutions?  No.  Should they be using the latest ‘"hammer" to solve all of their technology needs?  No.  What they need form IT is often less about development help and more about just good sound advice.  IT departments that aren’t enthusiastically getting into that advice business are going to be failing on many levels.

I truly do worry that SharePoint may become the next Lotus Notes.  Both SharePoint and Lotus Notes (which I used in the past and actually liked) put tremendous power in the hands of "end users".  (Maybe we should stop using the term "end users".  These days, everyone uses computers, and almost everyone dabbles in some sort of "development".)  Part of my mission as a SharePoint evangelist (read: enthusiast, junkie…) is to make sure that doesn’t happen.