German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Create a Simple Web Part for SharePoint 2007 using Visual Studio Extensions for SharePoint 2007 Development
Written By Omer Kamal On 07/10/2007

This Tutorial will create a Simple WebPart for Office SharePoint 2007 (MOSS 2007 and WSS 3.0). We will Create the SimpleWebPart in 12 easy Steps.

Views: 5606
Rating: 4.5
Login to Rate
omerkamal
Downloads: SimpleWebPart.zip
Tagged Under: WebParts, Microsoft SharePoint Server 2007, Microsoft SharePoint Services 3.0

Explanation:

We will create a Simple WebPart for SharePoint 2007 (MOSS or SharePoint Services 3.0). For Developing the WebPart we will use Visual Studio 2005 and Visual Studio Extensions for SharePoint 2007 Development.
We will create a Class library (.dll) and then Import that DLL to the SharePoint Manually.
1.      Create Class library in Visual Studio 2005.
2.      My SimpleWebPart Template (SimpleWebPart.cs) Code look like the Following:
 
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 SimpleWebPart
{
    [Guid("ab2d3f05-ddd7-4f4b-a392-06fdd6f68c49")]
    public class SimpleWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
        public SimpleWebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            // TODO: add custom rendering code here.
            // writer.Write("Output HTML");
        }
    }
}
 
3.      The Solution Explorer Creates On of each CS, Public key (.snk) and Assembly File. This will also automatically get reference of the Microsoft.Sharepoint Object.
4.      The WebPart is Inherited from   System.Web.UI.WebControls.WebParts.WebPart
 
5.      In the Render method add just one line of code:
 
protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("My simple WebPart for SharePoint 2007");
        }
 
 
6.      Now, Run the Project by pressing F5 key.
7.      The Visual studio Extensions for SharePoint 2007 Development will take care of exporting your WebPart to your SharePoint Default Web Application.
8.      After successful export Visual Studio will restart IIS and will pop-up with new Explorer window of your Default Web Application (Default Web Application uses Port- 80)
9.      To add the WebPart to your Site you need to open the edit mode of the Site. Click “Site Settings” (Site bearbeiten in German). We are using German version but rule of Thumb in SharePoint is that Menu Items have same locations.
10. Click the WebPart Zone to add your WebPart to it. It will bring a Pop-up in which all activated WebParts will be listed. Find your WebPart in the List and Check it.
11. Click “Add” (Hizufügen in German) to add the SimpleWebPart.
12.  You have your First WebPart in SharePoint now.
Delicious Digg reddit reddit Technorati
Downloads: SimpleWebPart.zip
About the Author:

@@ Omer Kamal is a Software Developer at Elanize KG Germany. He MSc. Mathematics from Islamia University Bahawalpur, Pakistan and Certified Developer from National Institute of Electronics Islamabad, Pakistan. He is Founder of FriendsPoint.de and Dotnet-Friends.com. He is currently Involved with Microsoft Office SharePoint 2007, Microsoft Dynamics CRM, BI Portal Solutions (Microsoft Dynamics Customization) and Web Security Solutions.
Check Omer Kamal Profile

Related Useful Links:
Visitors/Readers Comments
(for questions please use The Forum)



Arvind

Thanks for this helpful tip.

Thanks again.

17/01/2008 04:43:02 UTC

N.N
Greate and helpfull

27/01/2008 23:13:00 UTC

Genius
WOW man thats so informative. Did you get it from the microsoft site?

11/04/2008 06:55:05 UTC

Shamsu
Thanks a lot

It is very useful

26/04/2008 00:29:09 UTC

BEY

Thanks a lot for your guide.
This is my first share point webpart.
can i know how to make the webpart to other  web apllication?
(other than default web application - port 80, like port http://bey-server:42543 )?
Thanks

 

13/05/2008 01:27:15 UTC

Kamal
Hi Bey,

Your link is not working.

13/05/2008 04:30:10 UTC

Omar
Haha.

Kamal, I think he was just showing an example of what he means by other web application :) Bey-Server is on his local machine/network.

Anyway Bey, you can deploy it through Sharepoint Central Administration, go to Operations, Solution Management, and Click on the solution you want to deploy. Click on Deploy solution,  then select the web application from the list.

Hope that helps.

21/05/2008 21:25:50 UTC

caner
hi,i want to ask a question.

when i run my program,it shows this error;

c:\isnet\projects\web\webpart1\bin\debug\webpart1.wsp:the specified file was not found.

why is that?i couldn't understand.help me please.

26/06/2008 01:18:57 UTC

Walkingstar
 Thanks buddy.

Thankyou very much. I cud resolve some issues i had with the information you have posted here.


14/11/2008 13:27:25 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)