Friday, August 13, 2010

How to create the JQueryMin feature

The Goal
This entry will show how to create the JQueryMin feature with a web scope so that if we activate this feature on a site (not on a site collection) the jQuery Minified JavaScript library (v 1.4.2) will be load in every page of the site and therefore jQuery can be used on those pages.

Pre-requisites
I have installed on the web server Visual Studio 2008 with the VSeWSS13 (visual studio extensions for SharePoint) v 1.3, and the MOSS SDK v 1.5. With this you should be able to use the WSP Builder within VS2008. If that is not the case, please download and install WSP Builder from Codeplex.

Do-it
In VS2008, create a new Project and choose WSP Builder





Your Project will have the structure below


Right click the project name and choose add > New Item…, then choose from the WSPBuilder Blank Feature. Name it, give the description and give the scope (Web) in this case.

Right click TEMPLATE and add 2 Folders: LAYOUTS and CONTROLTEMPLATES. This last FOLDER is to add a web user control using the approach of Jan Tielens in his blog entry “INTEGRATING SHAREPOINT 2007 AND JQUERY [PART ONE]
The Features folder we don’t touch for the moment. On the Layouts folder we create a new folder named the same way as the feature and inside that new folder we add the js file you can download from jQuery.com.

On the CONTROLTEMPLATES Folder we have to create a web user control. Because this project is a WSPBuilder project, this item is not available. So we need to create temporarily and to support this project a new project. Right click on the solution and choose under Web the ASP.NET Web Application template. Name it and add a new item. Choose the Web User Control template. Call it the same as your WSPBuilder Project. If you double click on the control, you will see its code. Delete the code and replace it with:


Remove the 2 files attached under the web user control and copy it to the CONTROLTEMPLATES on the other project.
Remove the temporary web project.

In the elements file inside the tag elements create a tag named control which should reference your web user control:



Then build the project by right clicking on the project name and choosing WSPBuilder and Build WSP:

If the Build succeed you will see a new wsp file with the project name on the same folder as your solution folder of VS 2008.

If you wish to deploy it straight to the server where you have you build the project, right click again and choose WSPBuilder > Deploy.

Then to use it, you need to activate the feature on the site you wish.

If it is on a different server, take the wsp file there, and run:

Stsadm.exe –o addsolution –filename Projectname.wsp
Stsadm.exe –o execadmsvcjobs
Stsadm.exe –o deploysolution –name projectname –immediate –allowgacdeployment –allowCasPolicies –force