- SharePoint 2013 WCM Advanced Cookbook
- John Chapman
- 671字
- 2021-07-19 18:36:43
Creating and exporting a design package
Design packages in SharePoint 2013 allow us to package our customized branding from one SharePoint site and apply it to another. Design packages can include:
- Device channels
- Design files stored in
_catalogs/masterpage/
- Master pages
- Display templates
- Page layouts
When a design package is created, it will only include the preceding elements that were customized or added. It will not include the items that come by default with SharePoint. In this recipe, we will cover how to create a design package from a site that is already customized.
How to do it...
Follow these steps to create and export a design package:
- Navigate to the site in your preferred web browser.
- Select Site settings from the Settings menu.
- Select Design Manager from the Look and Feel section.
- There are eight steps present on the left-hand side of the page to manage every aspect of the SharePoint site design customizations that will be included in the design package. Perform each step to verify that the elements are being included in the site design package.
- Select the final step 8. Create Design Package as shown in the previous screenshot.
- Provide a Design Name.
- Select Create. Creating the design package may take some time depending on the amount of customizations being included and the server resources.
- Once complete, click on the link to download the design package.
How it works...
When creating a design package, each site design customization is reviewed in the wizard steps. These design customizations include master pages, page layouts, device channels, and design files (cascading style sheets, images, JavaScript, and so on). The design customizations are then packaged in a SharePoint solution file (WSP). These SharePoint solutions are sandboxed solutions that allow the site collection administrators to upload and deploy them rather than requiring a farm administrator.
There's more...
A design package may also be exported with PowerShell or with code using the server-side object model.
Follow these steps to create and export a design package using PowerShell:
- Load the
Microsoft.SharePoint.dll
andMicrosoft.SharePoint.Publishing.dll
assemblies into the PowerShell session.[Reflection.Assembly]::LoadFrom("C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Publishing.dll") [Reflection.Assembly]::LoadFrom("C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.dll")
- Get the site collection using the
Get-SPSite
Cmdlet.$site = Get-SPSite http://sharepoint/sitecollection
- Create the design package using the
Export
method ofMicrosoft.SharePoint.Publishing.DesignPackage
.$package = [Microsoft.SharePoint.Publishing.DesignPackage]::Export($site, "My PowerShell Design", $false)
- Get the filename using the specified format and design the package details.
$fileName = "{0}-{1}.{2}.wsp" –f ($package.PackageName, $package.MajorVersion, $package.MinorVersion)
- Get the
SPFile
object representing the design package WSP file from theRootWeb
property of theSPSite
object.fileBinary = $site.RootWeb.GetFile("/_catalogs/solutions/" + $fileName).OpenBinary()
- Use
System.IO.FileStream
to save the contents of theSPFile
object to the local filesystem.$fileStream = New-Object System.IO.FileStream("C:\" + $fileName, [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::Write) $fileStream.Write($fileBinary, 0, $fileBinary.Length) $fileStream.Close()
- Use the
Dispose
method to discard theSPSite
object.$site.Dispose()
Follow these steps to create and export a design package with code using the server-side object model:
- Get the site collection in a
using
statement.using (var site = new SPSite("http://sharepoint/sitecollection"))
- Get the root site of the site collection in a
using
statement.using (var web = site.RootWeb)
- Create the design package using the
Export
method ofMicrosoft.SharePoint.Publishing.DesignPackage
.var package = DesignPackage.Export(site, "My Code Design", false);
- Get the filename using the specified format and design the package details.
var fileName = string.Format(CultureInfo.InvariantCulture, "{0}-{1}.{2}.wsp", package.PackageName, package.MajorVersion, package.MinorVersion);
- Get the
SPFile
object representing the design package WSP file from theRootWeb
property of theSPSite
object.var fileBinary = web.GetFile("/_catalogs/solutions" + filename).OpenBinary();
- Use
System.IO.FileStream
to save the contents of theSPFile
object to the local filesystem.var fileStream = new FileStream("C:\\" + fileName, FileMode.OpenOrCreate, FileAccess.Write); fileStream.Write(fileBinary, 0, fileBinary.Length); fileStream.Close();
See also
- The SharePoint 2013 Design Manager design packages article on MSDN at http://msdn.microsoft.com/en-us/library/jj862342.aspx
- The SPWeb class topic on MSDN at http://msdn.microsoft.com/en-us/library/Microsoft.SharePoint.SPWeb.aspx
- The SPSite class topic on MSDN at http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.aspx
- The Get-SPSite topic on TechNet at http://technet.microsoft.com/en-us/library/ff607950.aspx