Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
Creating a custom WebPart in SharePoint 2007 isn't all that terribly difficult, just a few basic steps that may not be completely obvious...in addition if you want to deploy your WebPart on SP 2007 it may contain some additional resources such as gif's or java scripts. Wouldn't it be nice if you could just deploy one assembly with everything you need? Well that's possible so let's do that as well...
using
namespace
[
grdTime =
da.Fill(tblTime); grdTime.DataSource = tblTime; grdTime.DataBind(); Controls.Add(img); Controls.Add(new LiteralControl("<br/>")); Controls.Add(grdTime);
base.CreateChildControls(); }
protected override void Render(HtmlTextWriter writer) { writer.Write("<h4>Hello World!</h4>"); base.Render(writer); } }}
Before installing this to SharePoint 2007, let's complete this section by talking about what we need to do to embed the resources with the assembly.
You will also need to add using System.Web.UI; to the top of your AssemblyInfo.cs.
Finally in the code you can set the url of the image as:img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "SoftwareLogistics.SharePointTest.Images.Target.gif");
Now your assembly is ready to go all you need to do is turn that into and assembly and your are ready to incorporate it into your SharePoint 2007 site, you can even us this as a WebPart or even a standard Server Control on any ASP.NET 2.0 site.
To install the the component on the SharePoint2007 server you need to do the next couple of steps...
At this point SharePoint knows about your WebPart, but you'll need to make it part of the Gallery so open up your SharePoint site and do these final steps
At this point your web part is ready to be included just like any other WebPart.
Happy Coding!
- ec
Remember Me