views:

345

answers:

2

Hi

I've created a custom master page in sharepoint that comes with a lot of images (say 200). How do I package all the files to be provisioned to the Style Library of a site collection? The only way I know to do this is through a feature but that means listing every single file (all 200 of them) as a <file></file> element. Is there an easier way? The attribute IncludeFolders="??-??" in <module></module> doesn't seem to do anything.

If all the image files are in a folder inside my feature folder (e.g. ...\template\features\myFeature\images), is there a way to provision the entire folder to the Style Library?

Thanks.

+3  A: 

This module.xml file is in a folder named "Images". All the pictures are also in this folder (using the sharepoint development tools for visual studio 2008 v1.3). The wsp package need to know all the files that is adding so you have to add each file. (rename the .wsp to .cab and open it. You can then see all the files in the solution)

 <Elements Id="8f8113ef-75fa-41ef-a0a2-125d74fc29b7" xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
  <Module Name="Images" Url="Style Library/Images/myfolder" RootWebOnly="TRUE">
    <File Path="hvi_logo.bmp" Url="hvi_logo.bmp" Type="GhostableInLibrary" />
    <File Path="hvi_logo_small.bmp" Url="hvi_logo_small.bmp" Type="GhostableInLibrary" />
    <File Path="epj-logo.png" Url="epj-logo.png" Type="GhostableInLibrary" />
  </Module>
</Elements>

You could wirte a small C# app to create the xml file for you, something like this:

 var info = new DirectoryInfo(@"c:\pathToImageFolder");
        var files = info.GetFiles();

        TextWriter writer = new StreamWriter(@"c:\pathToImageFolder\module.xml");

        writer.WriteLine("<Elements Id=...");
        foreach (FileInfo file in files)
        {
            writer.WriteLine(string.Format("<File Path='{0}' Url='{0}' Type='GhostableInLibrary' />",file.Name));
        }
        writer.WriteLine("</Elements>");
        writer.Flush();
        writer.Close();
Tomso
Thanks for your response. Good suggestion to dynamically create the modules.xml file programmatically. I'm gonna try doing this.
A: 

Here's a quick Powershell function that works for me:

function Enum-FilesInPath
{
    param([string]$path)

    Get-ChildItem -path $path | foreach-object {
        # if a directory, recurse...
        if ($_.PSIsContainer)
        {
            $recursivePath = [string]::Format("{0}\{1}", $path, $_.Name)
            Enum-FilesInPath $recursivePath
        }
        # else if a file, print out the xml for it
        else
        {
            $finalPath = [string]::Format("{0}\{1}", $path, $_.Name)
            $url = $finalPath.Replace("\", "/") # backslashes for path, forward slashes for urls
            [string]::Format("`t<File Url=`"$url`" Path=`"$fullPath`" Type=`"GhostableInLibrary`" />")
        }
    }
}
ngm