Freigeben über


How to: Provision a File

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

To provision a file into SharePoint Web sites, you must use the Module element within a Feature or site definition. The Module element allows you to add one or more files, or file set, to a SharePoint Web site or document library.

Note

Windows SharePoint Services 3.0 supports provisioning a maximum 1000 files through Features, whether it be 1000 modules each with 1 file, or 1 module with 1000 files.

The Module element contains File elements that define which files to provision, and that can also contain definitions for the set of Web Parts to add. If you provision files to a subdirectory through the Module element, Windows SharePoint Services automatically ensures that the directory structure is created to match your files.

Through the Module element you can opt either to provision a file into a document library or to add a normal file (for example, default.aspx) outside a document library. In the case of adding a file to a document library, you must specify Type="GhostableInLibrary" as an attribute in the File element. This setting tells Windows SharePoint Services to create a list item to go with your file when it is added to the library. If you are instead provisioning a file outside a document library, specify Type="Ghostable".

The following example provisions a few new master pages into the master page document library.

Feature.xml

<Feature Id="947F6C32-E898-45f5-A595-C46F07DA6BF7"
  Title="New Master Pages"
  Scope="Web"
  xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="newmasterpages.xml" />
  </ElementManifests>
</Feature>

newmasterpages.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MPages" List="116" Url="_catalogs/masterpage">
    <File Url="Minimal.master" Type="GhostableInLibrary" />
    <File Url="ContosoRed.master" Type="GhostableInLibrary" />
  </Module>
</Elements>

The following example from a Windows SharePoint Services 2.0 site definition shows how to provision a file through the Onet.xml file. You can differentiate between where the file is located on disk and where it gets provisioned. Note that default.aspx is stored at dws\default.aspx relative to the root of the site definition, but is provisioned to /default.aspx in the site.

The example also shows how to use View elements to include list view Web Parts, as well as arbitrary Web Parts (AllUsersWebPart element) for adding non-list view Web Parts to the page. In addition, the example contains NavBarPage elements, which declare this page to be the home page of the SharePoint Web site.

<Module Name="DWS" Url="" Path="dws">
  <File Url="default.aspx">
    <View List="104" BaseViewID="3" WebPartZoneID="Top"/>
    <View List="103" BaseViewID="3" WebPartZoneID="Right" WebPartOrder="2"/>
    <View List="101" BaseViewID="6" WebPartZoneID="Left">
      <![CDATA[
        <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Title>Members</Title>
        </WebPart>
      ]]>
    </View>
    <View List="107" BaseViewID="7" WebPartZoneID="Left" WebPartOrder="2"/>
    <AllUsersWebPart WebPartZoneID="Right" WebPartOrder="1">
      <![CDATA[
        <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Assembly>Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
          <TypeName>Microsoft.SharePoint.WebPartPages.MembersWebPart</TypeName>
          <Title>Members</Title>
          <Description>Use the Members Web Part to see a list of the site members and their online status.</Description>
          <FrameType>Standard</FrameType>
          <IsVisible>true</IsVisible>
        </WebPart>
      ]]>
    </AllUsersWebPart>
    <NavBarPage Name="Home" ID="1002" Position="Start">  </NavBarPage>
    <NavBarPage Name="Home" ID="0" Position="Start">  </NavBarPage>
  </File>
</Module>

Provisioning a Folder

Use the Url attribute of the Module element to provision a folder as part of the module. The following example provisions a site with a folder called MyImages that contains a specified image file.

<Module Name="MyImage" Url="MyImages" Path="">
  <File Url="MyImage.jpg" Type="GhostableInLibrary" />
</Module>

See Also

Concepts

Module

Modules