다음을 통해 공유


How to: Provision a File

Applies to: SharePoint Foundation 2010

The following examples show how to provision files into various locations inside of Microsoft SharePoint Foundation. Each example uses the same project created in SharePoint development tools in Microsoft Visual Studio 2010.

Create the SharePoint Project

  1. Start SharePoint development tools in Visual Studio 2010.

  2. On the File menu, point to New, and then click Project.

  3. In Project Types, under Visual Basic or C#, select Module.

  4. Type FileProvisioning as the project name. Click OK.

  5. In the SharePoint Customization Wizard, choose Deploy as a sandboxed solution. Click Finish.

Deploy a New Master Page

You can deploy a master page to the master page gallery by using a module. The module XML is placed in the Elements.xml file that was created with the project. The XML deploys a master page to the master page gallery.

<Module Name="StarterMasterPage" List="116" Url="_catalogs/masterpage">
  <File Path="starter.master" Url="starter.master" />
</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 folder called MyImages that contains a specified image file. The module XML is placed within the Elements.xml file that was created with the project.

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

Provision a File Using an Onet.xml File

The following shows how to provision a file using the Onet.xml file. You can differentiate between where the file is located on disk and where it gets provisioned.

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.

The module XML is placed in the Elements.xml file that was created with the project.

<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="https://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="https://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>

See Also

Concepts

Module

Modules