Sunday, July 23, 2006

FW: SPS 2003 WebParts vs. ASP.NET 2.0 Webparts

 
ASP.NET 2.0 WebPart Framework is a new feature in ASP.net 2.0. Although Webparts existed in SPS 2003 times, this framework is completely new and follows its own architecture. The cool thing is ASP.NET 2.0 webpart framework is now compatible with latest version of sharepoint
i.e MOSS 2007.
This means ASP.NET 2.0 webparts can be used in Sharepoint 2007.

I wont repeat here the steps required to use your ASP.NET 2.0 webpart in Sharepoint 2007. You can see several blogs on this topic like:


http://weblog.vb-tech.com/nick/archive/2006/05/10/1563.aspx

http://msdn2.microsoft.com/en-us/library/ms431087.aspx


One main thing here to be kept in mind while creating custom webparts is that 2003 webparts dwp file uses different schema than Sharepoint 2007 webparts. If you try to use the ASP.NET webpart with old schema and try to import it in sharepoint you get the error:

The class does not derive from the Microsoft.SharePoint.WebPartPages.WebPart class and therefore cannot be
imported or used in a WebPartZone control

To resolve this ASP.NET webparts uses the different schema which is like this:

 

<?xml version="1.0" encoding="utf-8"?>
<webParts>
 <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
  <metaData>
   <type name="aspwebpart.FeaturePart, aspwebpart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
   <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
  </metaData>
  <data>
   <properties>
    <property name="Title" type="string">FeaturePart</property>
   </properties>
  </data>
 </webPart>
</webParts>




Using this schema you can easily import your ASP.net 2.0 webparts onto sharpeoint 2007.

The custom webparts you create can either be imported from
System.WEb.UI.WebControls.Webparts or Microsoft.Sharepoint.WebPartPages.Webpart

However if you plan to use feature like connections between webparts , you are left with
the option of using only deriving from Microsoft.Sharepoint.WEbPartPages.WebPart.

 


kick it on SharePointKicks.com

4 comments:

The Penns said...

I am using the v3 dwp schema in a MOSS solution CAB package to deploy the web parts. The web part deploys, but when you go to add the web part to a page in MOSS, it shows up under Miscellaneous with the name {guid here}_MyDwpFile.dwp.

Any thoughts on how to set this name? Thanks.

The Penns said...

Madhur said...

did you set the title tag inside the dwp file.

I did. The DWP has the Title and Description property elements set under the properties element. It's almost as if something is missing from the manifest.

Anonymous said...

We struggled in embedding a webpart (.net) in Site definition/layout. Finally we rebuilt our webpart using sharepoint libraries :-(

Glad to see information on this in your blog. Though late, would be useful in next project

Anonymous said...

Saved my butt! THanks for the info, it was driving me mad!

Dave