Not much work is needed to create a webpart in SharePoint (WSS or MOSS). I will show the simplest of webparts, so you can see how little work it takes.
1: Create a class library project, and add a reference to System.Web and Microsoft.SharePoint (rightclick “References” in “Solution Explorer”)
2: Create a batch (.bat) file to install in GAC
3: Sign the assembly (Properties on the project, bottom tab)
4: Add code (won’t be using actual SharePoint API, but you can do that as you wish, since we referenced SharePoint.dll)
01 using System;02 using System.Web;03 using System.Web.UI.WebControls;04 using System.Web.UI.WebControls.WebParts;05 using System.Web.UI;06 07 namespace HelloWorldWebPart08 {09 public class HelloWorld : WebPart10 {11 protected override void CreateChildControls()12 {13 base.CreateChildControls();14 this.Controls.Add(new LiteralControl("Hello, world! Welcome to Code-Journey.com"));15 }16 }17 }18
Remember to make the class public, otherwise you will not be able to add it to the SharePoint Web Part Gallery.
5: add safecontrol line to web.config
6: Go to the SharePoint Web Part Gallery (“Site Settings” and click “Web Parts” under the “Galleries” row.)
7: Click “New” in the top left corner.
8: Scroll through the list and check the “HelloWorldWebPart.HelloWorld” and click on “Populate Gallery”
9: Add the Web Part to any Web Part Page (try it on your front page) by clicking “Edit Page” in “Site Actions” menu. Click the “Add a Web Part” yellow link over the Web Part Zone you want to add it to.
10: A popup will appear. Click the + next to “All Web Parts” and and find the Web Part under Miscellaneous
Related posts:
- Repair broken Web Part Page in SharePoint / Remove Web Part From Page
- Make a SharePoint Application Page with CodeBehind
- How to create a new feature in sharepoint using Visual Studio
- How To Add A UserControl To A Web Part In SharePoint 2007
- The security validation for this page is invalid. Click Back in your Web browser…
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.