SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Developing a Custom Web Part with Microsoft Visual Studio 2008

This posting has a new location:

http://dougortiz.blogspot.com/2009/06/developing-custom-web-part-with.html

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:

  • <!--[if !supportLists]-->·         <!--[endif]-->Visual Studio 2005 Extensions for Windows SharePoint Services is not available or compatible with Microsoft Visual Studio 2008
  • <!--[if !supportLists]-->·         <!--[endif]-->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:

  1. <!--[if !supportLists]-->·         <!--[endif]-->Convert an existing template project from Microsoft Visual Studio 2005
  2. <!--[if !supportLists]-->·         <!--[endif]-->Create the project from scratch

<!--[if !supportLists]-->o   <!--[endif]-->Add the following references to the project:

System.Web;

Microsoft.SharePoint

<!--[if !supportLists]-->o   <!--[endif]-->Add the following code to the top of the project

using System.Web;

using System.Web.UI;

using Microsoft.SharePoint.WebPartPages;

<!--[if !supportLists]-->o   <!--[endif]-->Assign the class to inherit from the WebPart

public class MyCustomWebPart: WebPart

<!--[if !supportLists]-->o   <!--[endif]-->Add the RenderWebPart code:

protected override void RenderWebPart(HtmlTextWriter output)

{

}

<!--[if !supportLists]-->o   <!--[endif]-->Add desired code inside the “RenderWebPart”

<!--[if !supportLists]-->o   <!--[endif]-->Determine deployment type: bin or Global Assembly Cache

<!--[if !supportLists]-->o   <!--[endif]-->By default the Target Framework is 3.5

<!--[if !supportLists]-->o   <!--[endif]-->Deploy the Custom Web Part


Posted 11-30-2007 12:25 PM by DOrtiz

Comments

SHAREPOINTBlogs.com Mirror wrote Developing a Custom Web Part with Microsoft Visual Studio 2008
on 11-30-2007 2:31 PM

With the release of Microsoft Visual Studio 2008 many SharePoint Developers will be interested in creating

Alex Dresko wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 11-30-2007 2:57 PM

Actually, the development process is a great deal more complicated without the extensions. The biggest advantage of the extensions is the super easy CTRL+F5 to deploy your custom webparts. WSP View is also an incredibly useful tool which isn't available in VS 2008.

See forums.microsoft.com/.../ShowPost.aspx

for the current running conversation...

ahmed wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 12-01-2007 9:33 AM

that's a gr8 post,

don't you know how to use the MOSS extension for visual studio with VS 2008 to use the web part project template ?

DOrtiz wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 12-12-2007 1:26 PM

Ahmed,

Thank you for your kind comment.

The MOSS extensions works only for VS 2005, even though there are some workarounds to attempt making it does not work fully in VS 2008.

Check this link for more info:

forums.microsoft.com/.../ShowPost.aspx

Aimee wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 05-02-2008 3:33 PM

Can you pls explain in detain af creating a sharepoint webpart in visual studio 2008.

What is the difference between VS 2005 and VS 2008 as regards to webparts??

Help will be appriciated.

DOrtiz wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 05-04-2008 8:35 AM

Aimee,

The biggest difference is in VS 2008 you can create web parts that target different frameworks ( 2.0, 3.0 and 3.5 ) by just selecting the target framework on the project properties.

This is a very useful feature, but as a drawback most of the add-ons available for VS 2005 are not all readily available for VS 2008. One big useful add-on is the Visual Studio Extensions for Windows SharePoint Services, which is estimated to be available until June 2008.

Regards,

Doug Ortiz

Aimee wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 05-05-2008 10:12 AM

Thanks Doug for u r  reply,

But in VS 2005 If i need to create webparts i used to write a dll and all the structure of the webpart hard coded meaning writing td tr inside the cs page(I had not installed the extension) and then create a setup project to install that dll to the server where we have sharepoint installed ...  Is there any difference in this process ?? .... and also

Is there any webpart difference for frameworks (2.0, 3.0 and 3.5)

We r planning to move to VS 2008 from VS 2005 but Is that going to ease our life for webpart development ??

Doug wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 05-13-2008 8:02 AM

Aimee,

If you already have a template project for developing your web parts that can still be used in VS 2008, you will most likely have to update your template project ( back it up first just in case ).

Also, you can use the WSP Builder to help you with the process. This blog posting www.sharepointblogs.com/.../wspbuilder-extensions-v-1-01-released.aspx should give you insight into the add for VS 2005 and VS 2008 that is readily available.

Regarding the different frameworks, what this means is that you would be able to use other technologies with your web part if you would want to do that. For example, you could use technologies that are available to you when you select that Framework.

Developing in VS 2008 is a little faster but I would not un-install VS 2005 yet completely.

Doug

SF wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 07-02-2008 7:36 PM

For some reason RenderWebPart ( Writer ) does not work with Sharepoint Extensions in VS 2008. Any idea why ?.. I don't know an stuck cannot even write a webpart.

DOrtiz wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 07-02-2008 8:28 PM

SF,

Have you tried with WSP Builder instead?

You can download it at:

http://codeplex.com/wspbuilder

Regards,

Doug Ortiz

Freddie Davis wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 08-20-2008 7:32 PM

I have a web part built in VS2005 and want to upgrade it to VS2008 and it will not.  It says that .csproj is not installed and not supported.  I have verified that it is installed.  It works with ASP.Net sites and code but not web parts.  Can someone help me?

DOrtiz wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 08-21-2008 8:49 AM

Freddie,

I would open up VS2008 and create a new Solution Project; from there add the existing files from the solution into it.

You should be able to compile the web part, remember to choose which Framework you wish it to be targeted or leave the default.

Doug Ortiz

Bob wrote re: Developing a Custom Web Part with Microsoft Visual Studio 2008
on 01-02-2009 8:13 AM

Why has this been made so hard? Honestly - developing ascx controls in Visual Studio is so simple, and I cannot believe that Microsoft could not have conceived of a framework whereby you didn't have to build the UI in code.

Code-constructed UIs just don't work well in asp.net as maintaining state in dynamically created controls is so hard.

Microsoft really dropped the ball on this one.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.