November 2005 - Posts

One of the features that developers appreciate the most in Visual Studio 2005 is Code Snippets. Creating your own code snippets is quite easy, there’s even a code snippet for doing that. Now some code snippets have some kind of logic built-in, for example the constructor code snippet: it knows the name of the class for which you’d like to generate a constructor. If you would like to create your own code snippets with more advanced functionality you have to take a look at the Function element in the Literal element of the code snippet. Btw, here’s a nice gallery of free code snippets: http://www.gotcodesnippets.com/!

Very nice tip by Maxim Tarassenko: Programmatically create an unmanaged path under SharePoint. The following code snippet creates an excluded (unmanaged) path using the Object Model of Sharepoint. This can be very usefull to automate the install of Son of SmartPart, because the Microsoft tools (WPPackager and SPSAdmin) are not (yet?) working with .NET 2.0 assemblies.

            SPGlobalAdmin admin = new SPGlobalAdmin();
            SPPrefixCollection collection =
                admin.VirtualServers[2].Config.Prefixes;
            collection.Add("/unmanaged", SPPrefixType.Exclusion);

Btw: subscribed!

I'm looking for a SharePoint hosting provider which runs WSS SP2 and .NET 2.0, anybody knows such a company? My current hosting provider hasn't deployed SP2 yet because they have a "conflict" between SP2 and their "current system settings". Btw don't see this as negative comments, they have offer cheap SharePoint hosting: $9.95 per month, 2GB space, unlimited bandwith traffic and up to two WSS sites! (more info @ WebHost4Life).

Why do I need SharePoint hosting? Well I'm setting up a SmartPart showcase site, and what's better than Sharepoint to show off all the functionality! So if you browse to www.smartpart.info, you aren't redirected anymore directly to the GotDotNet workspace, but you'll see a (quite empty) WSS site. I'll keep you posted on the progress... :-)

One of the many new features in ASP.NET 2.0 is called Web Resources. Basically this allows you to store resources like images, scripts and so on, in an assembly. You can do this by using the WebResource attribute. This attribute can be applied on assembly level like this

[assembly: WebResource("image1.jpg", "image/jpeg")]
[assembly: WebResource("help.htm", "text/html", PerformSubstitution=true)]

If you want to use any of your resources in an ASP.NET form (or user control):

<img alt="help image" src=<% = WebResource("image1.jpg") %> />

When the page is rendered the image will point to something like
<img alt="help image" src=WebResource.axd?d=bWzAGpnwEO_jX-h7siKzTsDydsnTE8qDad/>

Many of the default ASP.NET 2.0 controls use this feature to store scripts and images, a good example is the TreeView control. If you want to use the same technique in SharePoint, for example when you want to run ASP.NET 2.0 user controls using the Son of SmartPart, you will face an issue. The problem is that the ISAPI filter of SharePoint will try to process the request to WebResource.axd, so you won’t be able to retrieve any resources. So as Hans suggested, I’m going to explain how to fix this.

To prevent that the ISAPI filter will try to process the requests to WebResource.axd, you have to exclude it as a managed path. On your SharePoint server, open up the SharePoint Central Administration site from the Administrative Tools start menu group and click the “Configure virtual server settings” link. On the next page you will see a list of all your virtual servers, click on the one that you would like to configure (you have to repeat the steps for each virtual server). Next, click the “Define managed paths” link. In the “Add a New Path” section, fill out WebResource.axd as the name of the path, for the type select “Exclude path”. Finally click the OK button. Now you can use WebResource in SharePoint sites!

Do you want to create web parts for SharePoint, but you don't want to buy/install a full blown Visual Studio? Well there is some good news! With the free Visual Web Developer 2005 you can create ASP.NET 2.0 Web User Controls, just like in Visual Studio 2005. So if you use the new Son of SmartPart (also free), you can show them in your SharePoint sites. There is however one limitation in Visual Web Developer, when you create the Web User Control all the server side code (C# or VB.NET) will be put in the ASCX file as well. So don't look for .CS/.VB files or DLL's, just copy the .ASCX to the UserControls folder and you're good to go.

Designing the user control in Visual Web Developer:

The same user control in SharePoint:

When I talk to BizTalk developers about the new Windows Workflow Foundation I always have to explain the difference between BTS and WWF. There are a couple of good blog posts discussing the differences:

But Stephen Kaufman nails it in his latest post: "So, to summarize, Windows Workflow is great for workflow within an application whereas BizTalk is great for workflow across applications and this is precisely why BizTalk shines in Enterprise Application Integration scenarios."

This article will show you how you can create your first .NET 2.0 user control and show it in a SharePoint site. First you need to deploy the Son of SmartPart to your SharePoint server of course. Check the Installation Guide which you can find in the zip file that can be downloaded from www.smartpart.info, or watch this installation screencast. When this is done, open up your brand new Visual Studio 2005 and create a new ASP.NET Website. In the Website menu choose “Add new item”, and add a new Web User Control to the project, named DemoControl.asxc.

Now let’s implement the desired functionality! Drag-and-drop a Calendar control from your toolbox on the newly created Web User Control. You can do this both in design and source view, but in the source view you immediately see the result. You can use the SmartTag to Auto Format the control, I’ve selected the professional look of course. :-)

It’s time to write some code so switch to code view, and in the Page_Load event write following code:

public partial class DemoControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Calendar1.Width = new Unit("100%");
        Calendar1.SelectionMode = CalendarSelectionMode.None;
        Calendar1.TodaysDate = DateTime.Now;
    }
}

Optionally you can test your user control by putting it on your default.aspx page for example. But lets immediately fast forward to the deployment of your work to SharePoint. Open the folder in which your web site is located (typically \My Documents\Visual Studio 2005\WebSites\NameOfSite) and copy DemoControl.ascx and DemoControl.ascx.cs to the \UserControls folder of your SharePoint site (check the installation guide if you don’t know what I’m talking about). Next you can open the SharePoint site where you’d like to add the user control as a web part. On the top right of the page, click “Modify Shared Page”, “Add Web Parts”, “Browse” and drag-and-drop an instance of the SonOfSmartPart UC web part to your page.

Click the “Open the tool pane” link on the SmartPart and select the “usercontrols_democontrol_ascx” from the top drop down. Additionally you can also choose a title for your web part. When you’re done click the OK button at the bottom of the page. Now you’re ASP.NET 2.0 UserControl is displayed in a SharePoint site!

This is very cool: now you can host email for your own domain(s) for free at domains.live.com. Just register a domain somewhere, add an MX record so it points to a Microsoft DNS server and you're ready to go (detailed instructions are available when you subscribe). The result is that you can read/send/manage email for whateveryouwant@yourdomain.com in a Hotmail-style interface. Domain names are pretty cheap nowadays, with this service on live.com having your own custom email address will be accessible for everybody.

Have us host e-mail and IM for you in a domain you already own.

  • Create up to 20 e-mail accounts within your domain
  • Get a 250 MB inbox for each account*
  • Check your e-mail from any Web-enabled PC
  • Junk e-mail filter protection using Microsoft SmartScreen technology
  • Virus scanning and cleaning of e-mail
  • Seamless access with MSN Messenger, MSN Spaces, etc.

The only drawback for Europeans is the small star on the second line; appearantly we only get 2 MB of space ... :-( Anyway, it's your turn google.

*250MB inbox available only in the 50 United States, District of Columbia, and Puerto Rico. Eligible Hotmail users will first receive 25MB at sign-up. Please allow at least 30 days for activation of your 250MB storage to verify your e-mail account and help prevent abuse. Microsoft Corporation reserves the right to provide 250MB inbox to free Hotmail accounts at its discretion.

Last week I was in Denmark to deliver an intensive training/coaching session for WM-Data. The topics included SharePoint, VSTO, Office, BizTalk, … and the combination of all of them. There are a couple of things that I learned over there:

  • Aarhus is not a suburb of Copenhagen, in fact the two cities are more than 300km away from each other.
  • A lot of Belgian beer is sold in Aarhus, I even found a beer that is browed in my home town: Achel Trappist!
  • Visual Studio 2005 Code Snippets are always well received, developers love them.
  • VSTO 2005 simplifies the life of Office developers a lot: no more ISmartDocument, SmartTags are now fun to develop and Outlook is now a platform as well.

I’m back in Denmark in two weeks (5 to 9 December), this time in Copenhagen. Drop me a line if you’d like to get into the Christmas mood together with me. :-)

Here’s some good news for everybody that has been waiting for it: I’ve just uploaded the brand new Son of SmartPart to the GotDotNet site! First of all, what is the Son of SmartPart? This version of the SmartPart will allow you to run ASP.NET 2.0 Web User Controls and ASP.NET 2.0 Web Parts in SharePoint sites. Since WSS SP2 you can run your SharePoint sites on the .NET Framework version 2.0, and from now on you can use the power of the new platform to extend SharePoint.

What is working and what is not?
Not all features that I would like to be in v1.0 are available yet, so what is already working and what’s not? The Son of SmartPart (SOSP) comes in two flavours: one to run ASP.NET 2.0 User Controls (SOSP-UC) and one to run ASP.NET 2.0 Web Parts (SOSP-WP). For the SOSP-UC version, all the features from the previous version of the SmartPart are working, so you can expose custom properties, toolparts, create connectable web parts and so on. The SOSP-WP version only has the basic functionality to run ASP.NET 2.0 web parts. Advanced stuff like connections are not yet supported. Support for these advanced features will follow.

How do you install it?
If you download the release from the GotDotNet site, you will find an Installation Guide. I’ve also created a small screencast to guide you to this process. There is no automated installation yet because the current version of the deployment tools (STSADM and WPPackager) do not support .NET 2.0 assemblies (yet?).

What's next?
This is not the last release of the Son Of SmartPart! I'd love to hear your feedback so we can make the coming releases even better. For now: go get the latest version on http://www.smartpart.info and unleash the power of ASP.NET 2.0 on your SharePoint sites!

More Posts