Search This Blog

Thursday, October 28, 2010

Developing and Deploying Custom Web Parts for SharePoint Portal 2007

Development of Web Part in VS 2005
To Get Started with creating Custom Web Part for MOSS 2007 in Microsoft Visual Studio 2005, Open the IDE and create a new C# project, Select Class Library as Project Type. Name It as NewWebPart.

Add a reference to the System.Web  from .Net components into the project. The System.Web dll contains the required namespace ofSystem.Web.UI.WebControls.WebParts .

In The Project explorer view rename the Class1.cs with NewWbPart.cs to be consistent with this example; this will result in renaming the Class name as well. With the help of “using” keyword include the namespaces as shown in the code example below. Derive / Extend the NewWebPart Class from the WebPart Class ( System.Web.UI.WebControls.WebParts.WebPart), and add the code as shown below. The CreateChildren Control is same as in .Net 1.1, that it would create and add controls to this Web Part Class,. In this case I have only added a WebControl.Calender Object. The RenderControl Method is an override for the WebPart Base Class and calls the RenderChildren Method, this causes the Children Controls to be rendered on the Particular HtmlTextWriter passed as a parameter to the method

using System;
using System.Collections.Generic;
using System.Text;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace NewWepPart
    public class NewWebPart : WebPart

        protected override void CreateChildControls()
            Calendar cldr = new Calendar();
            cldr.Enabled = true;
            cldr.ShowGridLines = true;
            cldr.ShowTitle = true;
            cldr.EnableViewState = true;
      cldr.SelectedDate = DateTime.Now;

            Controls.Add(cldr);       �

        public override void RenderControl(HtmlTextWriter writer)



 Build the project and on successful built you are ready to Deploy the Web Part to the Portal Site.

Deployment of Web Part:
In order to deploy a web part to a SharePoint portal 2007 site, we must have the URL of the site to which we want our web part needs to be deployed (displayed in fact). As it  is mentioned earlier that the Web Parts developed in .Net 2.0 environment does have a .CAB project , instead an assembly is created on build of project. Now there are two choices to deploy the assembly to the SharePoint portal directory.
  • Deploy the assembly to the Assembly Folder (GAC) (requires the assembly to be stron named).
  • Put the assembly to the bin folder of the portal directory.
For the sake of simplicity, the later choice is being demonstrated in this example.

Putting Assembly in Bin Folder:
The MOSS 2007 creates every portal in the inetpub\wwwroot\wss folder. The easiest way to find the bin folder from these folder hierarchies is to go from inetmgr console. Locate the appropriate portal (for which u want to deploy the web part), identified with the port number. Right click and have Properties. Under the Home Directory Tab, note the path in Local path text box. Verify if the bin folder exists in the specified path by opening it in browser. If the folder doesn’t exist then create one. Now copy the assembly form the project output folder and paste it in bin folder of portal.

However there is another work around for putting the assembly in to the portal’s bin folder again ad again each time the Web Part Project is built with changes.
Right click on the project name (NewWebPart) in the VS.Net 2005 IDE and click properties. Under  the Build page paste the same path copied from inetmgr console into the Output Path. As shown in figure below. This will result in the latest assembly automatically deployed to the bin folder every time the project is built.

Adding the Safe Control Entry:
Even though the assembly is present in the Portal’s Bin folder, there is another step required to make the Control (Web Part) assembly usable on the Portal Pages. Since the control will need to render on multiple machines in different browsers with as many user accounts as the organizations have. There is a need to declare the control as “safe”. To do so open the web.config file placed under the portal’s directory in the VS.Net 2005 IDE.

Then edit the file in the section of SafeControls, create a new SafeControl entry for our assembly as shown below. Save the file and close it.

<SafeControl Assembly="NewWebPart" Namespace="NewWebPart" TypeName="*" Safe="True" />

Configuring Portal to use NewWebPart
Since now the web part have been written and deployed to the desired portal’s directory. The next task is to use the web part on the Portal’s Site. The Web Part Deployed to the portal can be placed on any site within that Portal. For convenience this NewWebPart is demonstrated to be placed on the home page of default Portal.
Open the portal site in the internet explorer; in this case http://oss1 is the URL for the default portal, ensuring that the current logged in user has the administrative rights on the portal site.

To begin with, the first step is to add the newly deployed web to the Portal’s web part gallery, since the portal is using the configuration databases to keep record of the contents of the portal, our newly created web part’s information doesn’t exist in the database. We need to add the web part to the Web Part Gallery before we can use it.

To do so, the following steps should be followed.
  1. Click on the Site Actions button and then select Site Settings.

2.On the site settings page under Galleries column click on the Web Parts.

3.On the Web Part Gallery Page click on the New button, to add the new web part assembly to the gallery.

4.On the New Web Parts page locate the NewWebPart in the list, check the check box on the left and click on the Populate Gallerybutton the top of the page. This will result in the Web Part entry creation in the Web Part Gallery list, and hence it can be used from now on from the gallery. It can be notices easily that the Web Parts developed form the new Frame work of 2.0 have an extension of .webpartafter their names. Whereas in earlier versions, it was a .dwp file. Both the .webpart  and .dwp  files are the XML definition of the Web Part.

  1. Until this step the web part is ready to be used on the site by selecting it from Web Part Gallery. Click on the Site Actions button on the page and then select Edit Page, this will modify the appearance of the page to enable the edit view. In this view Web Part Zones are highlighted so that a user can add a web part to the zone, Click on the Add a Web Part button in the left zone to add the Web Part.

6.Select the NewWebPart from the web part list . it is found under the Misc section and then click on�Advanced Web Part gallery and options.

7.In the�Add Web Part Pane at right , select Home  Gallery and then drag the NewWebPart from the pane into the Web Part Zone.

8.Click on the Exit Edit Mode link on the page and the site will return to the view mode.


  1. Diverse kinds of workout techniques and work outs
    can be achieved during this products.

    Feel free to surf to my homepage :: best adjustable dumbbells

  2. Sports activities drinks switch the electrolytes
    lost by sweat a lot quicker than drinking water.

    Here is my web page ...

  3. How accurately can adjustable dumbbells save you area?

    Visit my web blog dumbells sets

  4. Obviously squats, but I could now also load the bar for the
    rack and do standing calf raises, barbell lunges, military press, dips
    (utilizing the dip handles) and most likely by far the most surprising chin-ups.

    Also visit my web site - cheap bowflex selecttech 552 dumbbells

  5. Until finally the earlier handful of several years if females needed to exercise they had to visit
    gyms attended by men too.

    Here is my webpage - adjustable dumbbell set

  6. The Bowflex Greatest 2 dwelling health and fitness center also features state with the art Electrical power Rod technologies that is a verified system that offers the same resistance
    of dumbbells but with out the jarring effect which will damage joints and tendons.

    Here is my web blog - incl Post Article Comments Name : EmailAddress : URL : Comments : Article Categories �

  7. One of the best ways to guarantee that you simply obtain the
    full benefits of performing exercises with resistance bands is usually to utilize them to assist your circuit

    my homepage free weights for sale

  8. If you're aerobically match, your body normally takes in and utilizes oxygen additional successfully -- to maintain the repetitive muscle motion.

    Here is my site full dumbbell set

  9. I talked to a variety of individuals and did fairly a bit of research on the net, but almost everything which i listened to
    and examine went back and forth about which was superior,
    so I decided that if I was going to order some, I really should possibly consider
    them both equally out and see which I liked greatest.

    Visit my web-site

  10. So, acquire the pedometer and begin counting ways.

    my homepage - dumbbell set adjustable

  11. In advance of you buy, just ensure which the treadmill looks like
    it really is completely new.

    Also visit my homepage ...

  12. You should use weights or dumbbells to do this training.

    Here is my homepage ... adjustable weights

  13. Now let us take into account what happens in case you don't work out therefore you lose 1/2 pound of muscle a year from age forty to age 50.

    Check out my site -

  14. You need to burn up far more than you take in.

    Also visit my blog - bowflex dumbbells 552

  15. If so, then the Bowflex Treadclimber could be an excellent equipment for
    you personally.

    My web-site :: bowflex selecttech 552 dumbbells sale

  16. In compound pushing movements, even so, these kinds of as being the
    squat and numerous presses, the somewhat flat resistance curve provided with the near vertical motion of
    a barbell will supply a comparatively balanced variation in resistance.

    Here is my homepage ... free weight dumbells

  17. After you go about your daily life, you pick up things in a single hand far
    more usually than with two.

    Feel free to surf to my blog; bowflex dumbbells 552

  18. Like other conditioning treadmill equipment manufacturers, it could also
    be folded, but you ought to program the place you may set
    it, cause as soon as you've received assembled it's a key job to transfer as a result of its 298+
    pound bodyweight.

    Visit my webpage: Highly recommended Website

  19. Do you have a spam problem on this website; I also am a blogger, and I was wanting to know your situation; many of us have developed some
    nice methods and we are looking to swap strategies
    with other folks, why not shoot me an email if interested.

    Feel free to surf to my web site :: Muscle Rev Xtreme Trial

  20. These mutations somewhat diminish, but do not nearly completely inhibit, the normal function of alpha-glucosidase.

    Humans, naturally, do not like bitter flavors or foods. Having a six-pack or eight-pack abdomen is a dream for
    thousands of people, which is further fortified by the screen shots of their favorite actors who
    have the perfect physique with muscular arms and chest.

    Visit my web site: Buy Power Pump XL

  21. It could be utilised by anyone with relieve.

    Also visit my web page - gyms

  22. Ηі, I dο belіeve this is an excellent webѕite.

    I stumbledupon it I will return yеt again since I
    bookmarked it. Mоney anԁ freedom is the
    best ωay tο сhаnge, may you
    be rіch and cοntinue to guide othеrs.

    Feel free to surf to my homeρage core training with pialtes

  23. There’s definately а greаt deal to κnow about this
    issue. I like all the points yоu have made.

    Take a look аt mу web-site; loѕing weіght aftеr 50 (

  24. Ι uѕed to be able to find goοd info from yοur content.

    my web-site: green works

  25. I blog often аnԁ I seriοusly apprеciate youг informatіon.
    The article has reallу pеаked my interest.
    І'm going to book mark your site and keep checking for new information about once a week. I subscribed to your RSS feed as well.

    Also visit my website: core training exercise