This is a small tutorial to get you started with the new SharePoint 2007 extensions for Visual Studio.NET 2005. I’ll cover here the basics for building a Web Part to get you started.
Step 1 is to install of course the extensions. They can be downloaded over here.
Next, open up Visual Studio.NET 2005 and you can create a new project selecting the SharePoint project type. Different templates are available amongst one is the template to build a Web part.
A class is created, all of the references are in place and also you have the option now to configure the feature that will make your Web part available in the site collection you are going to target. To see that feature configuration place, right-click the project and open the properties page in the designer. There is a new tab called SharePoint Solutions. Activating it shows the details of the feature. For the Hello World sample, pretty much everything is filled in and you do not have to change anything.
While you are in the properties page, activate the Debug tab and type in the URL of the site collection where you want to see your Web Part popping up.
Now return to the class representing your Web Part. The only thing we will worry about for this basic tutorial is just outputting the string Hello World:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace HelloWorld
{
[Guid("2ad93b4c-6f33-4942-bcc9-cbb8b2597610")]
public class HelloWorld : System.Web.UI.WebControls.WebParts.WebPart
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write("Hello Dudes!");
}
}
}
You are ready to rock :). Press F5 and you’ll start the process of deploying the Web Part as a feature to the server farm.
Open up the site you are targetting and in the Site Settings page, navigate to the Site Collection Features page. You’ll notice that the Web Part is listed as a feature that is already activated.
That entails that you now can go to one of your pages and just add it to the page as one of the Web Parts.
Now don’t laugh! I know it is pretty simple but you can now start building more complex Web Parts. And didn’t I hear Jan talking about his plans to integrate the Smart Part in all of this?
Anyway, interesting things happened behind the scenes when you pressed F5. Basically, Visual Studio.NET created a SharePoint 2007 solution for you. You can browse to that solution in the file system. It is the HelloWorld.wsp file in the bin\debug folder of your project. This is a CAB file and you can see its contents extracted in the underlying solutions folder. Here you will find the DLL and the feature that makes the Web Part available. Remember features are not about deploying things, features are about making things in SharePoint 2007 available.
The manifest.xml actually tells the tool that installs the solution where everything needs to end up.
The DLL goes into the GAC, the registration is done as a safe control and the feature files are copied in the Features folder in the 12-hive. So what is that tool that installs the solution? Well it is good old STSADM.EXE that has now a new option called addsolution. You can verify all of this in the setup.bat found in the bin\debug folder. Now go to the SharePoint 3.0 Central Administration. In the Operations page, you find a link called Solution Management. You can see here the deployed solutions. This is the place where the admins can manage all of the deployed solutions and possibly remove them.
Good stuff from the product team! It is really going to give a boost in the productivity of many Web Part developers.