Search This Blog

Showing posts with label VS 2008. Show all posts
Showing posts with label VS 2008. Show all posts

Monday, June 1, 2009

Developing a Custom Web Part with Microsoft Visual Studio 2008

With the release of Microsoft Visual Studio 2008 many SharePoint Developers will be interested in creating custom Web Parts for SharePoint. This is entirely achievable and not very different from how it is done within Visual Studio 2005.

While the avenues to accomplishing this are similar with Microsoft Visual Studio 2005, there are a few items to consider:

  • Visual Studio 2005 Extensions for Windows SharePoint Services is not available or compatible with Microsoft Visual Studio 2008
  • As a good practice, it is recommended to backup your project before converting it into Visual Studio 2008

Creating the Web Part Project can be done in two of ways:

  • Convert an existing template project from Microsoft Visual Studio 2005
  • Create the project from scratch
    • Add the following references to the project:

      System.Web;

      Microsoft.SharePoint

    • Add the following code to the top of the project

      using System.Web;

      using System.Web.UI;

      using Microsoft.SharePoint.WebPartPages;

    • Assign the class to inherit from the WebPart

    public
    class
    MyCustomWebPart: WebPart

    • Add the RenderWebPart code:

    protected
    override
    void RenderWebPart(HtmlTextWriter output)

    {

    }

    • Add desired code inside the "RenderWebPart"
    • Determine deployment type: bin or Global Assembly Cache
    • By default the Target Framework is 3.5
    • Deploy the Custom Web Part

Should I Use Visual Studio 2008 as my only development environment for SharePoint?


Visual Studio 2008 was Released To Manufacturing this past November 19, 2007, by now a multitude of SharePoint enthusiasts have most likely downloaded or installed it on their development environments.

They probably are wondering whether to keep the current install of Visual Studio 2005 or not; this is the purpose of this posting to help you assess whether or not you should un-install Visual Studio 2005 and use solely Visual Studio 2008 for your development environment.

These are the issues to consider:

  • Visual Studio 2005 Extensions for Windows SharePoint Services 3.0 does not work in conjunction with Visual Studio 2008.

    The node for SharePoint does not exist when creating a new project, even if you un-install and re-install the Visual Studio 2005 Extensions for Windows SharePoint Services 3.0.

  • Visual Studio does include under the Office 2007 Node the following workflows:
    • SharePoint 2007 Sequential Workflow
    • SharePoint 2007 State Machine Workflow


  • Visual Studio 2008 allows you to choose your target Framework
    • This is accomplished by going to the Project properties in the Application Tab, a dropdown named TargetFramework is now available

Conclusion

While the development of Custom Web Parts, Site and List Definitions for SharePoint does not exclusively depend on Visual Studio 2005 Extensions for Windows SharePoint Services 3.0, it is not readily available in Visual Studio 2008.

Therefore, if you do not use the VSE for WSS you can go ahead and un-install it. Otherwise, you might have a use for it if using Visual Studio 2005 Extensions for WSS once in a while.