Whilst messing with a product some contractor of ours did for us (SURJIT I’m talking about you).  I discovered a lovely piece of code.

The SiteDef had some SiteProvisioning code, it read an XML file to do additional processes as part of the site provisioning, rather handy in some cases.

But I did notice a few oddities.

In SiteProv he was creating lists.  Also He was copying files from the file system into Lists.  Some users just don’t have access to this part of the file system and this was exploding.

Two things about this technique,

  • 1st. You can Provision Lists in the ONET.
  • 2nd You can copy files into lists in the ONET.

The first item he should have known, so WHY do it as part of site provisioning event ?  I don’t know. Perhaps something to do with sequence, perhaps stupidity ;-).

Second I can forgive, someone not trained in SharePoint might not know exactly what the <Module> Tag is really for.

Think of the <Module> tag in Features and SiteDefs as a kind of File copy as well as configuring what webparts go where on a page, it can copy files from the file system into a DocLibrary, but most importantly it has the correct rights to do it.

Some extra info on ONET’s and Modules.

From all the examples you have seen in existing SiteDefs the most likely arrangement would be something like this

 <Project>
    <Configurations>
        <Configuration ID="0" Name="Default">
            <Lists>
               <List FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" Type="101" Title="MyPlaceForFiles" Url="MyPlaceForFiles"/>
            </Lists>
            <Modules>
                <Module Name="Default" />
            </Modules>
        </Configuration>
    </Configurations>       
    <Modules>
        <Module Name="Default" Url="" Path="">
            <File Url="default.aspx" NavBarHome="True">
                <AllUsersWebPart WebPartZoneID="LeftZone1" WebPartOrder="0">
                    <![CDATA[…..WebPart Stuff…….]]>
                </AllUsersWebPart–>
            </File>
        </Module>
    </Modules>
</Project>

So in the example I mentioned where I want to copy a file from my SiteDef into a List would go something 

<Project>
    <Configurations>
        <Configuration ID="0" Name="Default">
            <Lists>
               <List FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" Type="101" Title="MyListForFiles" Url="MyPlaceForFiles"/>
            </Lists>
            <Modules>
                <Module Name="Default" />
                <Module Name="WhatASecondModule" />
            </Modules>
        </Configuration>
    </Configurations>       
    <Modules>
        <Module Name="Default" Url="" Path="">
            <File Url="default.aspx" NavBarHome="True">
                <AllUsersWebPart WebPartZoneID="LeftZone1" WebPartOrder="0">
                    <![CDATA[…..WebPart Stuff…….]]>
                </AllUsersWebPart–>
            </File>
        </Module>
        <Module Name="WhatASecondModule" Url="MyListForFiles" Path="FolderItCameFromOnDiskInSiteDef" RootWebOnly="FALSE">
            <File Url="SourceFileIWantToChangeOnFlyInDocLib.js" IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary"/>
        </Module>
    </Modules>
</Project>

The thing to notice here is that there is a Second Module entry in the Config Section, this module has a different function to the standard one so needs a second declaration.  The rest of the syntax in the module is straight from the documentation, I have a folder to copy to (URL) in this case its a DocumentLibrary, I have a Path that the file on the disk lives, in my case I have a sub folder in the SiteDef to store this file so I put that as its Path, if its in the root then leave it blank, Then in the <FILE> tag I define what files to copy etc.

Technorati Tags: ,,
Advertisements