Day of the Developer

Living the life of a developer. What is development work really like?

<April 2008>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Post Categories

Article Categories

News

I'm a dad :) Welcome to a new life.

Navigation

Software Business Tips

My Sites

Subscriptions



Importing User Controls into WSS 3.0

This is insane.

I have a user control test.ascx. It is a valid user control, containing nothing but a string of text to display. In an ASPX page derived from the Sharepoint base page type, it displays perfectly happily as a web part.

I put a copy in the sharepoint root, and try to upload the following web part file for it (and yes, I've done all the SafeControl, etc settings for it.

<?xml version="1.0" encoding="utf-8" ?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type src="~/Test.ascx" />
<importErrorMessage>
Error: Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">
TEST</property>
<property name="Description" type="string">
TEST</property>
</properties>
</data>
</webPart>
</webParts>

And when I try to preview the webpart I get: The element is required. Add this element to the Web Part file (.webpart), and then try to import the Web Part. at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean

When I put it in a virtual directory and change the webpart file to this:

<?xml version="1.0" encoding="utf-8" ?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type src="~/_customcontrols/Test.ascx" />
<importErrorMessage>
Error: Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">
TEST</property>
<property name="Description" type="string">
TEST</property>
</properties>
</data>
</webPart>
</webParts>

I now get: Exception of type 'Microsoft.SharePoint.WebPartPages.WebPartPageUserException' was thrown. at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart

Now, both files validate, and point to a real location, etc, etc, but the second file matches what I really want to do, and the error message is completely meaningless. There are about 14 places in CreateWebPart that exception might be thrown, but they should all have a message to display.

I run SharePoint in full trust to remove any security issues, still the same problem. I log / write info from a static constructor, never happens. This tells me it is something to do with the webpart file. But how do I find out?

posted on Wednesday, April 30, 2008 10:47 AM by admin

# re: Importing User Controls into WSS 3.0 @ Tuesday, November 25, 2008 5:26 PM

Microsoft lied.
Sharepoint DOES NOT SUPPORT USER CONTROLS.
I used reflector to check the sharepoint source code, and although the definition file validates, and loads with no error, the src attribute is never even checked.

Roger Willcocks

Powered by Community Server, by Telligent Systems