C# – My existing webparts won’t work in SharePoint

asp.netcdeploymentsharepointweb-parts

I have a standard ASP.NET 2.0 website.
It has a webpage page.
I have a webpart in my Company.Web.dll that I display on my webpart page on my website.
All is good!!!

I would like to use this same webpart in SharePoint 2007.

I have a "site definition" project in VS2008 using Extensions for SharePoint 1.2. I have tried various ways to add the webpart from an outside assembly to my site definition. I have been able to deploy the webpart (where it is added to the webpart list of a webpart page) but I have been unsuccessful at adding the it to a page.

My Glorious Failures:

  1. Created a shell webpart to just display the existing web part, basically just using my part as a control.
  2. Attempted to modify the X.webpart and X.xml files created by VS2008 when you create a new webpart.

Both result in the following error while adding the web part to the page:

Exception
Microsoft.SharePoint.WebPartPages.WebPartPageUserException:
Cannot import XXXX Web Part.
at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean
clearConnections) at
Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager
manager, XmlReader reader, Boolean
clearConnections, Uri webPartPageUri,
SPWeb spWeb) at
Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager
manager, XmlReader reader, Boolean
clearConnections, SPWeb spWeb) at
Microsoft.SharePoint.WebPartPages.WebPartQuickAdd.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)

Is there a special way I need to add my existing webpart to my site definition?

Best Answer

This sounds like a problem resolving the GUID at deployment time, as you can read about in this SO question.