Condividi tramite


Use modules to include files in the solution

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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 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:

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

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, Path="Module1\Sample.txt".

- Url: The location where the file will be deployed on the SharePoint server. The format is, Url="Module1/Sample.txt".

- Type: An 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