I'm using Visual Studio 2008, and have downloaded VSeWSS.exe 1.2, to enable Web Part development. I am new to SP development, and am already bewildered by the number of different versions of SP, and the VS add-ons. This particular problem has come up, which highlights my confusion.
I selected Add - New Project - Visual C# - SharePoint- Web Part, accepted the defaults, and VS created a project, with the main file WebPart1.cs
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace WebPart1
{
[Guid("9bd7e74c-280b-44d4-baa1-9271679657a0")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
public WebPart1()
{
}
protected override void CreateChildControls() // <-- This line
{
base.CreateChildControls();
// TODO: add custom rendering code here.
// Label label = new Label();
// label.Text = "Hello World";
// this.Controls.Add(label);
}
}
}
The book I'm following, Essential SharePoint 2007, by Jeff Webb, has the following for the default project -
using System;
<...as previously>
namespace WebPart1
{
[Guid("9bd7e74c-280b-44d4-baa1-9271679657a0")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
// ^ this is a new style (ASP.NET) web part! [author's comment]
protected override void Render(HtmlTextWriter writer) // <-- This line
{
// This method draws the web part
// TODO: add custom rendering code here.
// Label label = new Label();
// writer.Write("Output HTML");
}
}
}
The real reason for my concern is that in this chapter of the book the author frequently mentions the distinction between "old style" web parts, and "new style" web parts, as noted in his comment on the Render method.
What's happened? Why has my default Web Part got a different signature to the authors?