Dot Net Mafia

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

October 2009 - Posts

The developer dashboard is a great new feature that developers can use to aid them in tuning performance on a page. This new functionality adds information to the bottom of any page in SharePoint that displays performance information and what SQL queries were executed to display the page. To my knowledge, there is currently no way in the UI to turn this on, so you can do this with a quick x64 console application. This is soon to become a quite popular code snippet I am sure.

This is already starting to be an interesting topic, so I wanted to post about it. We’ll start with the facts.

SharePoint 2010 only runs on 64 bit operating systems

In the past, SharePoint developers have pretty much always had to develop in a virtual environment

Windows Virtual PC does not support 64 bit guests but other non-Microsoft virtualization technologies do

SharePoint 2010 can run on Windows 7 / Vista x64

Most developers do not want to run a server OS on their development machine

Some developers may still be running 32 bit operating systems (ack!)

So what does this mean? For some reason, Microsoft has not given us desktop virtualization software that can run 64 bit guests (even though Hyper-V can). So I think this left Microsoft a choice. Get 64 bit guests added to Windows Virtual PC, recommend developers use a non-Microsoft virtualization technology, or get SharePoint working on Windows 7 and Vista. Now, adding 64 bit support I am sure is quite an undertaking and they definitely don’t want to recommend a competitor’s product. This means that making SharePoint work directly on the developer’s machine the obvious choice. After all it runs on top of IIS and IIS is pretty similar between Windows Server 2008, Windows 7, and Windows Vista (yes, I do know there are differences).

Now, I think it will be interesting to see what path developers choose here. Many developers I am sure probably already were using another virtualization software such as VMWare. For them, they are pretty much unaffected and will probably continue to developer in their VM. By now, I think most SharePoint developers have it engrained in them that they must develop on a VM, but maybe they will change their mind. People are so accustomed to thinking that development must be done in a VM, I hear them asking not when the beta 2 install will be available, but when will the VM be available? My answer is always well even if you have a VM, you aren’t going to be able to run it unless you are running Hyper-V or it was made with VMware.

Personally, I think I like the idea of running SharePoint on my laptop. I lose some flexibility that the VM gives me but I also gain some convenience of not having to maintain multiple versions of Visual Studio and what not. Will it affect performance of my laptop? Absolutely, but that just gives me a chance to ask for better hardware. :) Of course, if you are in a company where you have little control of your hardware, getting upgraded to Windows 7 x64 could be an issue.

UPDATE: @spmcdonough reminded me in a comment about booting a VHD natively with Windows 7. This option was actually brought up in the Patterns & Practices talk at SPC. They of course did not mention any competing virtualization solutions. :) It certainly is a way to get some good VHD performance by running the operating system natively. This may be a good option for some people but probably not for me. I don’t want to have to leave everything behind in my Client OS while I am doing my development. Sure you could install all the various things that you use from your client environment onto that VHD but then aren’t you just replacing your client OS with a server OS? It is an interesting option though. It may not work for me, but it might for some. Although I have to say I might consider it if I had a second machine available.

UPDATE (01/04/2010): So Beta 2 has been out for a while and I have actually tried a number of options. I started out trying VMWare Server running on my Windows 7 laptop. I was still looking for a free option. This worked ok, but not great. Since VMWare Server is designed for servers, it has no issues about taking every available resource on your machine for your VMs whether it needs it or not. This made going back to the host machine just to check Outlook or visit a web site somewhat painful. Adding more memory helped, but it still wasn’t ideal. So I decided to try Sun VirtualBox. The first thing I liked about it was the fact that I was able to take my VMWare hard disk file and boot it directly with VirtualBox without going through any type of conversion process. It just worked. I tried it with several VMs and it really does work great. The performance of the VM also feels a bit better and my host machine still has plenty of resources left to do whatever I need it to. If you are looking for a free option and don’t feel like dual booting, I definitely recommend giving VirtualBox a try.

So what do you think you are going to do? Are you going to install it locally on your Windows 7 machine? Go with VMware? Install Windows Server 2008 on your laptop maybe? Quit SharePoint development? :) There are pros and cons to each approach. I’d love to hear your plan. Leave a comment and tell us your plan.

SharePoint 2010 brings a few new master pages that you may want to know about. There are additional master pages to accommodate both the old and new versions of UI. There are also some simplified pages to take note in.

The first master page we will talk about is v4.master. This is the default team site master page used with version 4 (obviously) of the UI. This will be the master page you typically use. It provides the ribbon bar and all of the other new visual UI changes such as the site actions menu on the left side.

If you did an upgrade to SharePoint 2010 and haven’t transitioned to the new UI yet, the old master page is still in default.master. This looks just like the master page you use in SharePoint v3 today. It doesn’t have the ribbon bar and the site actions menu is still on the right side.

The search pages by default now use minimal.master. This is a really slimmed down master page with next to nothing on it. It doesn’t even have navigation. I’m not sure why they opted to use this page in Search Center, but I think it provides and issue with people trying to leave the search center. The Office Web Applications also use this master page but that makes a little more sense because it provides more screen real estate.

The last page I will mention is simple.master. This page is used for login and error pages. From what I understand, it can’t be customized (I have no idea why), but it can be replaced.

I hope this helps if you were curious about the new master pages. I’ll also remind you again that application pages can also now make use of any branded master pages you might have created. I’ll also point out that the master pages all use properly formed XHTML although I am not sure about default.master. I will check that when I get a chance.

With MOSS 2007, I often got asked what order do I install these solution packages in. Oftentimes, it was critical that they get installed in a particular order. With features, we have had the ability to set dependencies, but we really didn’t have anything like that for solution packages. Well, I haven’t heard people talking about this new feature yet, but we can in fact set solution dependencies in the manifest.xml file.

The way it works is that it checks to see if a dependent solution has already been deployed on your farm (or site collection for sandbox solutions). However, it won’t chain deploy child solutions for you like you can do with hidden dependent features. It does this check when you attempt to deploy the feature (not when you add it). It also won’t remove a parent solution should you remove any of its dependent child solutions. Solution dependencies will also work between sandbox and farm solutions. Here is what the XML looks like that you will put in your manifest file.

I attended numerous Search sessions at SPC09 and one thing that I was excited to see is there have been a few improvements in the keyword syntax that will pretty much eliminate the need to use Full Text SQL queries any longer. In fact, the impression I got from my last search session is that Full Text SQL queries are pretty much considered dead and they should not be used (but they will still work).

The first thing you should know is that you can query SharePoint Search or FAST Search with the keyword query syntax. There is no need to learn a different syntax to do basic queries with FAST. FAST does have its own query language called FQL, but we’ll talk about that some time in the future. Now for the exciting stuff.

Keyword queries now support prefix matching. This is huge. If you are reading this I am guessing you have a customer that has asked for wildcard searching. This is going to eliminate a lot of your headaches. You can query on a single term or on a managed property. Here are some examples.

I am very excited that I will be able to retire the Wildcard Search Web Part. It simply will not be needed any more and this keyword syntax will make it much easier to get better results off of wildcard queries.

Another cool feature is support for Boolean operators. Before, the keyword query syntax really only effectively supported AND between terms. You can now do either. Here is an example.

“Red” OR “Green”

You can also group things together using parenthesis and use the AND operator as well. This gives you a lot more flexibility now and will make it so you rely less on Full Text SQL queries to do these kinds of searches.

The last thing that I will mention is that you can use operators now in keyword queries to search against non text fields. For example, you could query using a managed property greater than a certain value. The syntax looks like this.

RecordCount>100

As you can imagine, these improvements largely eliminate the need for writing Full Text SQL queries and doing huge customizations to the search center.

One new ECM feature that not too many people have talked about is the concept of default values for site columns. It turns out that you can use default values to do metadata inheritance. The way it works is that if you have a custom content types for your folder and child items, you can set default values on the folder and when a new document is created it will automatically set those values on the child content type. We used to have to write code to do this back in MOSS 2007.

After hearing about this new feature, I decided to go to the HOL while I was at SPC and see if I could get it to work. I created two new content types and created a new folder. When I brought up the ECB for the folder I saw a new item that said something to the effect of Set Default Values on this Folder. Here I was able to set values on my site columns. I then uploaded a document to the folder and viewed the properties and sure enough it had the default values I specified. I then used the new document button inside the folder and I noticed that the Document Information Panel did not have the default values. I saved the document to see if they would get set then, but they in fact did not. Now I don’t know if that is a bug or is by design or not. I guess only time will tell.

Either way, I think this is a good start and will definitely eliminate some code we have to write in the future. What I would really like to see next is an option to apply default values to all child items when there is a change (kind of like how you can apply changes to a content type).

Curious to know what the Services on Server page looks like now? Well, then this is the post for you. Instead of just having the 6 or so services that you had in MOSS 2007, there are many more services listed on the Services on Server page. Here is what your list might look like (pending changes of course).

Access Database Service

Application Registry Service

Business Data Connectivity

Central Administration

Document Conversion Launcher Service

Document Conversion Load Balancing Service

Excel Calculation Services

Lotus Notes Connector

Managed Metadata Web Service

Microsoft SharePoint Foundation Incoming E-mail

Microsoft SharePoint Foundation Subscription Settings Service

Microsoft SharePoint Foundation Web Application

Microsoft SharePoint Foundation User Code Service

PerformancePoint Service

PowerPoint Service

Search Query and Site Settings Service

Secure Store Service

SharePoint Foundation Search

SharePoint Server Search

User Profile Service

User Profile Synchronization Service

Visio Graphics Service

Web Analytics Data Processing Service

Web Analytics Web Service

Word Automation Services

Word Viewing Service

As you get more familiar with the concept of Service Applications, you will notice that many of the items on this list are service applications.

Microsoft really answered the call of developers by adding several new events that developers had been wanting in MOSS 2007. Event better, Visual Studio 2010 really makes it easy by using the new Add Event Receiver wizard. It provides an interface with all of the possible things you might want to implement and then creates them in a class for you. When it comes to feature receivers, I’ll point out that SPFeatureReceiver no longer requires you to implement every method. You can now just create Event Handling methods for the events you care about.

Here is a list of the new events.

FeatureUpgrading

WebAdding

WebProvisioned

ListAdding

ListAdded

ListDeleting

ListDeleted

WorkflowStarting

WorkflowStarted

WorkflowPostponed

WorkflowCompleted

Hopefully, what the events do is obvious from their names. Of course, the name of these events might change at some point in the future. I would like to see the WebProvisioned event be renamed WebAdded personally.

If you are like me when you get a new product, you look at every possible little thing you can find to see what’s new or different. That’s why I post this today because I figured you might be interested in what the databases might looks like in the next version. Of course, as usual this is subject to change in the future. In a typical installation, MOSS 2007 had a good number of databases. It looks like SharePoint 2010 more than doubles the number. My particular installation had 22 databases. I think this number can even grow even more as you activate more Service Applications. Most of the names are obvious, but I have commented on a few of them. Some of the databases have spaces in their names. The names are determined based upon how the service application was named.

Application_Registry_Service_<guid> – not sure if this is for the old Business Data Catalog or not.

Bdc_Service_db_<guid>

Managed_Metadata_Service_<guid> – likely for the new metadata term store

With MOSS, it seemed like most web part developers tended to avoid changing the version of their DLL, because it lead to numerous headaches as you had to update the .webpart file. You also had to update any page that you might have the web part on as well so that it would load the new version. What’s nice about SharePoint 2010 is that your manifest file in your solution package can now deploy binding redirects to your web.config. For example, this means you can have any reference to version 1.0.0.0 redirect to use version 2.0.0.0. Binding redirects are nothing new to .NET, it’s just that SharePoint is now taking advantage of this feature. In fact, SharePoint uses this feature itself to redirect any calls to its DLLs from version 12.0.0.0 to 14.0.0.0. Here is an example of what that might look like.

This is another topic that is quite dear to most SharePoint developers. We’ve all been there. We want to know if a list item exists and the indexer is useless. It throws an exception should we attempt to access an item that does not exist. Well as we discovered this week there is a new TryGetList method that works great to determine if a list exists but there really isn’t anything new with a SPBaseCollection. We can do this a number of ways include spmetal.exe to generate strongly typed classes, but I was looking for a solution that didn’t require me to generate any classes. We can now use .OfType<T> to get an IEnumerable<T> that we can use. Once we have IEnumerable<T> it is quite easy to determine if a list item exists using the .Any() method. Look at the example below.

As you can see using the lambda expression p => p.Name we can do a comparison to see if a list item with that name exists. This will return us a boolean if the item does in fact exist. As you can see this isn't quite as good as a native method that checks for an item that exists, but it does work. If you want to get creative you can also check on other fields such as Title, Id, or whatever. Take a look at this sample.

listEnumeration.Any(p => p["Title"] == "List Item 1");

listEnumeration.Any(p => p.UniqueId == someGuid);

As you can see, LINQ makes it quite easy to determine if an item exists. This may not be the most efficient way to do it as it is rather brute force. It may only be arguably better than using a try / catch block, but it certainly looks cleaner.

You might have seen that there is a new designer for working with web parts in Visual Studio 2010. This is actually, not quite the case, so I thought I would share with you how it actually works. When you use the Visual Web Part SPI (SharePoint Project Item), it will create a number of files for you: a .cs file, a .webpart file, an elements.xml file, and a .ascx file. That’s right, it creates an ASP.NET user control. Now, the Visual Studio interface does a nice job of grouping all of the files together. When you open the designer on the web part, you in fact just open the designer for the user control.

So now you might be thinking, how does this work? Well no SharePoint can’t host user controls directly still. In fact all it does is create a simple web part with a Page.LoadControl() method pointing at our user control. This in fact is the same method we’ve been using for years to get user controls into SharePoint. I don’t really see this as an issue though, since Visual Studio does a great job making it painless to deploy these now and use them inside SharePoint.

This is a bitter subject with most MOSS 2007 developers because the most common way to do this is by using a try/catch block when you try to use the indexer on SPListCollection. Well, I am pleased to tell you about a new method I discovered on SPListCollection that really made my day. The new TryGetList method takes the name of a list and will get this, return a null if the list doesn’t exist. Take a look at this code.

That’s right! You heard me, instead of throwing an exception, you actually get null back when the list doesn’t exist. No more try/catch blocks. No more extension methods to hide those try/catch blocks. Unfortunately, there is nothing on SPBaseCollection to check if an item exists, but I do have a solution, so be looking for that post.

Apparently, Microsoft thought the number thirteen was unlucky. Now, I know they are trying to rebrand this as the SharePoint root (or something like that), but we all know that is never going to sick, so I’ll just call it the 14 hive. Anyhow, this is the new place you’ll be doing a lot of your work. Although with the new Visual Studio 2010 tools, you’ll find that you won’t need to come to this folder nearly as much. In this post, I thought I would take a brief moment to point out what I noticed in the 14 hive and make any comments as necessary. None of the underlying folders really have changed but a few things have been added.

In the root of the 14 Hive, I noticed three new folders

UserCode – files used to support sandboxed solutions

WebClients – used for the client OM I believe

WebServices – many new .svc files

If you are interested in what assemblies are present in the ISAPI folder, here is a quick list. It sounds like some classes have moved to different DLLs, but I haven't encountered any yet.

There are a number of feature improvements in SharePoint 2010. They have made many changes which allow you to do more with features when they are activated or upgraded. One of the new features it the ability to write to the property bag. To do this we just make use of the new PropertyBag element in your elements.xml file. Here is what a file might look like that writes to the property bag. As usual, I’ll point out that features or syntax could change.

<Elementsxmnlns="http://schemas.microsoft.com/sharepoint/">

<PropertyBagParentType="Web">

<PropertyName="MyCustomProperty1" Value="some value" />

<PropertyName="MyCustomProperty2" Value="4" />

</PropertyBag>

</Elements>

I will point out that whatever type you initialize the property with, it will become semi-permanent. Currently, this applies for integers and date/time. If you try to save another type in an existing property later, you will end up with a null value being stored. This will save me some time in the future as I have had to write code to do this in the past.