Using Modules to Include Files in the Solution
There may be times when you may want to deploy files to the SharePoint server regardless of their file type, such as new master pages. To do this, you can use Modules (not to be confused with Visual Basic code modules). Modules are containers for files in a SharePoint solution. When the solution is deployed, the files in the module are copied to the specified folders on the SharePoint server.
To create a module, add it to a project by choosing it in the Add New Item dialog box. Then, modify its Elements.xml file to include the names of the files you want to deploy, where they are located on the system, and where they should be copied on the SharePoint server.
Here is an example of the Elements.xml file for a module:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="Module1"> <File Path="Module1\Sample.txt" Url="Module1/Sample.txt" /> </Module> </Elements>
Newly-created modules contain the following default files:
|Elements.xml||The definition file for the module.|
|Sample.txt||A placeholder file that serves as an example of a file in the module.|
The Elements.xml file contains the following elements:
|Elements||Contains all of the elements defined in the module.|
|Module||The module element has a single attribute, Name, that specifies the name of the module in the format |
Note that if you change the name of the module (or its Folder Name property), you must manually update the name in the Module element.
If you specify a subdirectory for the file(s) in the Module element, Windows SharePoint Services (WSS) will automatically create a matching directory structure for them.
|File||The File element has two parameters, Path and Url.|
- Path: The name and location of the file in the SharePoint solution. The format is,
- Url: The location where the file will be deployed on the SharePoint server. The format is,
- Type: An optional attribute that has two settings: GhostableInLibrary and Ghostable. The format is,
Each file that you want to deploy requires a separate
<File> element entry in Elements.xml.