How to: Provision a File
Published: May 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.
-
Start SharePoint development tools in Visual Studio 2010.
-
On the File menu, point to New, and then click Project.
-
In Project Types, under Visual Basic or C#, select Module.
-
Type FileProvisioning as the project name. Click OK.
-
In the SharePoint Customization Wizard, choose Deploy as a sandboxed solution. Click Finish.
Use the Url attribute of the Module1 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>
The following shows how to provision a file using the Onet.xml2 file. You can differentiate between where the file is located on disk and where it gets provisioned.
The example also shows how to use View3 elements to include list view Web Parts, as well as arbitrary Web Parts (AllUsersWebPart4 element) for adding non-list view Web Parts to the page. In addition, the example contains NavBarPage5 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="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>
Type
=
"
GhostableInLibrary
" is mandatory , in VS 2010 the module will create a folder for the master page gallery and it will provision the master page file in it. If we didn't specify the type, the folder will be in "Pending" status and we can't see the master page file once we visit the master page gallery, ( yes we can see it in the SPD). Once we specity the type Type ="GhostableInLibrary" then both folder and master page file will be added and approved at the time installation of the feature.
- 9/24/2010
- sowmyancs