Friday, March 07, 2008



HOW TO DEPLOY A WEBPART THAT HOSTS A WEB USER CONTROL TO SHAREPOINT

There are a couple of different ways to create the web part and deploy it to Sharepoint, but here is how I did it. In my case, I developed locally on my machine( I did copy the Sharepoint dlls locally for reference). The deployment server was on a virtual machine where I had MOSS setup.

1. Create the Web User Control(with code behind) in Visual Studio.

2. Sign the Assembly so that it has a strong name

3. Create the web part (either Sharepoint Webpart or ASPNET Webpart) in Visual Studio. Another good article for reference

4. Sign the Assembly.

5. Go to the Sharepoint Deployment Server.

6. Copy both the above strong named Assemblies(user control and webpart assemblies) to GAC on the Sharepoint server

7. Modify security settings of Sharepoint site by changing the Trust to Full in Web.Config of the Sharepoint Site like this..
trust level="Full" originUrl="" />

8. Add Safe Control Entries to the DLLs added to GAC in Web.Config of the Sharepoint Site similar to this.. ( I used Reflector to get the strong name)
SafeControl Assembly="SmartParticles, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=70d581d0b6a14330" Namespace="WebParticle" TypeName="*"
Safe="True" />
( I used Reflector to get the strong name)

9. Add an Assembly element to the assemblies section of Sharepoint site’s web.config file..similar to this.

assemblies><

add assembly="SmartParticles, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=70d581d0b6a14330"
/>

>
>


10. Create a Folder usercontrols under the Sharepoint site ex: wss/VirtualDirectories/80/usercontrols. Make sure this is not an application in IIS, as otherwise, it will fail.

11. Copy the ascx file(web user control file) and the other css files, xslt files and images(used by the user control) to this usercontrols folder. Make sure that when you access these other files from inside your user control code, they are referenced as “/usercontrols/*.gif” and so on.

How to populate the Web Part Gallery with the added Webpart.
The user needs to be the administrator of the site in order to do this.

Open the main Sharepoint site and go to Site Actions->Site Settings->Modify All Site Settings and click Webparts under Galleries.

Click New..this will by using Reflection populate the new webpart from the safe controls list in web.config.

Select the new web part and click “Populate Gallery” to place it in the gallery.

The webpart is now availableto populate on any of the Webpart pages inside Sharepoint.

See the webpart from my Test Sharepoint Site below:

No comments: