【问题标题】:Sharepoint Branding - Multiple File ProvisioningSharepoint Branding - 多文件配置
【发布时间】:2010-09-15 22:17:29
【问题描述】:

我在 sharepoint 中创建了一个自定义母版页,其中包含大量图像(例如 200 个)。如何打包所有要预配到网站集样式库的文件?我知道这样做的唯一方法是通过一个功能,但这意味着将每个文件(全部 200 个)列为<file></file> 元素。有没有更简单的方法?属性 IncludeFolders="??-??"在<module></module> 似乎没有做任何事情。

如果所有图像文件都在我的功能文件夹内的一个文件夹中(例如 ...\template\features\myFeature\images),有没有办法将整个文件夹配置到样式库?

谢谢。

【问题讨论】:

    标签: sharepoint branding


    【解决方案1】:

    此 module.xml 文件位于名为“Images”的文件夹中。所有图片也在此文件夹中(使用 Visual Studio 2008 v1.3 的 sharepoint 开发工具)。 wsp 包需要知道正在添加的所有文件,因此您必须添加每个文件。 (将 .wsp 重命名为 .cab 并打开它。然后您可以看到解决方案中的所有文件)

     <Elements Id="8f8113ef-75fa-41ef-a0a2-125d74fc29b7" xmlns="http://schemas.microsoft.com/sharepoint/">
      <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>
    

    您可以编写一个小型 C# 应用程序来为您创建 xml 文件,如下所示:

     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();
    

    【讨论】:

    • 感谢您的回复。以编程方式动态创建 modules.xml 文件的好建议。我会尝试这样做。
    【解决方案2】:

    这是一个适用于我的快速 Powershell 函数:

    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`" />")
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多