Share via


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.

Module Items and Elements

To create a module, add it to a project by selecting 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="https://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:

File Name

Description

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:

Element Name

Description

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 <Module Name="Module1">.

NoteNote
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.

Attribute NameDescription
PathThe name and location of the file in the SharePoint solution. The format is, Path="Module1\Sample.txt".
UrlThe location where the file will be deployed on the SharePoint server. The format is, Url="Module1/Sample.txt".
TypeAn optional attribute that has two settings: GhostableInLibrary and Ghostable. The format is, Type="GhostableInLibrary". Specifying GhostableInLibrary means the file will be added to a document library in SharePoint together with a list item to accompany the file when it is added to the library. Specifying Ghostable causes the file to be added to SharePoint outside the document library.

Each file that you want to deploy requires a separate <File> element entry in Elements.xml.

See Also

Tasks

How-to: Include Files by Using a Module

Other Resources

how to: provision a file

Developing SharePoint Solutions

Creating Web Parts for SharePoint

Packaging and Deploying SharePoint Solutions