Friday, 30 August 2013

Deploy jQuery to site assets library using SharePoint solution package

n this article we will discuss about how to deploy jQuery files to SharePoint Asset library, so that it will be available to the particular site collection only.


Follow below steps:
Step-1:
Open Visual Studio 2010, and choose File -> New Project. And then Select SharePoint -> 2010 -> Module. Give a Name to the project DeployjQuery, and click OK. Remember to select .Net framework version 3.5 as shown in the figure below:

Step-2:
In the next step select the local deployment URL and select "Deploy as a sandboxed solution".

Step-3:
Now if you will open the solution explorer it should be look like below:

Step-4:
In the next step Rename the Module1 module to Assets, and delete the Sample.txt file. Remember after doing this the Elements.xml file contains also changed accordingly.

Step-5:
Now copy the jQuery files and put it inside the Assets folder. Now the elements.xml file will change automatically but you need to add URL attribute to the Module like below:

<Module Name="Assets" Url="SiteAssets">

The full elements.xml file should be like below:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Assets" Url="SiteAssets">
  <File Path="Assetsjquery-1.6.2.min.js" Url="Assets/jquery-1.6.2.min.js" />
</Module>
</Elements>

Now if you deploy and check the Site Assets folder the jQuery files should be there.

But before deployment it is good to give a good name to the feature.

So expand the Features folder and rename Feature1 to jQueryFeature and then double click on jQueryFeature.feature. From there change the Title and Description and also you can set the Scope of the feature.

Now you can deploy the solution. Once the deployment is over the jQuery files can be browse like below:
http://URL/SiteAssets/DeployjQuery/jquery-1.6.2.min.js

No comments:

Post a Comment