Daniel Larson (www.portal
Guest
|
Posted:
Mon Nov 07, 2005 9:51 am Post subject:
WALKTHROUGH: VS 2005 WebPart |
|
|
In response to several NG posts, here is a BASIC walkthrough of creating a
simple WebPart for SharePoint using VS 2005.
1. Create a new project (class library).
2. Add a reference to C:\Program Files\Common Files\Microsoft Shared\web
server extensions\60\ISAPI\sharepoint.dll (assuming default US English
install... adjust the path accordingly).
3.Create a new WebPart class. Here is an example for BarPart in a
FooParts.proj:
-------------------------------------------------------------------
/* In web.config:
* <SafeControl Assembly="FooParts" Namespace="FooParts" TypeName="*"
Safe="True" />
* This assumes the assembly name is FooParts
*/
namespace FooParts
{
public class BarPart : Microsoft.SharePoint.WebPartPages.WebPart
{
protected override void CreateChildControls()
{
this.Controls.Add(new System.Web.UI.LiteralControl("hello fellow
SPGeeks"));
}
}
}
-------------------------------------------------------------------
4. Copy the dll to the bin directory.
5. Add the SafeControls entry to web.config (as in the code comment above).
6. Go to the newdwp page to add your new webpart to the gallery:
http://localhost/_layouts/1033/NewDwp.aspx
7. Now add it to your page.
That's it. Here are some clarifications:
-Whidbey WebParts are not SharePoint WebParts. Make sure you inherit from
the Microsoft.SharePoint.WebPartPages.WebPart class.
- Make sure you're running SP2 and are running the website in ASP.NET 2.0.
Please reply if you have any problems getting this running.
Daniel Larson
http://feeds.feedburner.com/daniellarson |
|