Export (0) Print
Expand All

How-to: Include Files by Using a Module

Modules (not to be confused with Visual Basic modules) are containers that enable you to deploy files such as ASPX master pages, text files, or images to SharePoint.

You can choose to deploy a file into a document library or as a normal file (for example, default.aspx) outside a document library. To add a file to a document library, specify Type="GhostableInLibrary" as an attribute in the File element. This setting instructs SharePoint to create a list item to go with your file when it is added to the library. To deploy a file outside a document library, either specify Type="Ghostable" or just omit the Type attribute.

To add a module

  1. Open or create a SharePoint project in Visual Studio. For more information, see SharePoint Project and Project Item Templates.

  2. In Solution Explorer, select the project node and then click Add New Item on the Project menu.

  3. In the Add New Item dialog box, select Module in the list of SharePoint templates and then click Add.

    This creates a new node in the project named Module1.

  4. Click Sample.txt under Module1 and delete it.

    Sample.txt is included in all new modules for example purposes and is not needed. (Note that deleting the file also removes its entry from the module's Elements.xml file.)

  5. If you want your files to deploy to a particular folder structure in SharePoint, create those folders under Module1 in Visual Studio. To do this, click Module1 and then select New Folder on the Project menu.

  6. Right-click the folder in which you want to add the file and then click Add Existing Item on the Project menu.

  7. Select one or more files that you want to deploy to SharePoint and then click Add.

    When you add a file to the project, an entry for it is automatically added to the module's Elements.xml file. When the project is deployed, the files are copied to SharePoint server, relative to the project's root directory, which is specified by the File element's Url attribute, such as Url="Module1/New Folder/SomeFile.doc. If you want to change the deployment location for a file, either move it to another folder in Solution Explorer or change its Url setting.

  8. For any files that you want to appear in a document library, append the Type="GhostableInLibrary" attribute to their entry in Elements.xml. For example,

    <File Path="Module1\Some Folder\SomePage.aspx" Url="Module1/Some Folder/SomePage.aspx" Type="GhostableInLibrary" />
    
  9. Deploy the project.

    The files copy to the specified locations in SharePoint.

Community Additions

ADD
Show:
© 2014 Microsoft