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:

  1. Navigate to the site in your preferred web browser.
  2. Select Site settings from the Settings menu.
  3. Select Design Manager from the Look and Feel section.
    How to do it...
  4. 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.
    How to do it...
  5. Select the final step 8. Create Design Package as shown in the previous screenshot.
  6. Provide a Design Name.
  7. Select Create. Creating the design package may take some time depending on the amount of customizations being included and the server resources.
  8. 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.

Creating and exporting a design package using PowerShell

Follow these steps to create and export a design package using PowerShell:

  1. Load the Microsoft.SharePoint.dll and Microsoft.SharePoint.Publishing.dll assemblies into the PowerShell session.
    [Reflection.Assembly]::LoadFrom("C:Program FilesCommon Filesmicrosoft sharedWeb Server 
    Extensions15ISAPIMicrosoft.SharePoint.Publishing.dll")
    
    [Reflection.Assembly]::LoadFrom("C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.dll")
    
  2. Get the site collection using the Get-SPSite Cmdlet.
    $site = Get-SPSite http://sharepoint/sitecollection
    
  3. Create the design package using the Export method of Microsoft.SharePoint.Publishing.DesignPackage.
    $package = [Microsoft.SharePoint.Publishing.DesignPackage]::Export($site, "My PowerShell Design", $false)
    
  4. Get the filename using the specified format and design the package details.
    $fileName = "{0}-{1}.{2}.wsp" –f ($package.PackageName, $package.MajorVersion, $package.MinorVersion)
    
  5. Get the SPFile object representing the design package WSP file from the RootWeb property of the SPSite object.
    fileBinary = $site.RootWeb.GetFile("/_catalogs/solutions/" + $fileName).OpenBinary()
    
  6. Use System.IO.FileStream to save the contents of the SPFile 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()
    
  7. Use the Dispose method to discard the SPSite object.
    $site.Dispose()
    

Creating and exporting a design package with code using the server-side object model

Follow these steps to create and export a design package with code using the server-side object model:

Note

A reference to the Microsoft.SharePoint.Publishing.dll assembly is required for this recipe.

  1. Get the site collection in a using statement.
    using (var site = new SPSite("http://sharepoint/sitecollection"))
  2. Get the root site of the site collection in a using statement.
    using (var web = site.RootWeb)
  3. Create the design package using the Export method of Microsoft.SharePoint.Publishing.DesignPackage.
    var package = DesignPackage.Export(site, "My Code Design", false);
  4. 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);
  5. Get the SPFile object representing the design package WSP file from the RootWeb property of the SPSite object.
    var fileBinary = web.GetFile("/_catalogs/solutions" + filename).OpenBinary();
  6. Use System.IO.FileStream to save the contents of the SPFile 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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.142.85