Importing and applying a design package
With SharePoint 2013, a user only needs to be a site collection administrator to apply a packaged design rather than be a farm administrator. This offloads the burden of applying site collection level designs from farm administrators and makes it simpler for site collection administrators to obtain packaged designs from third parties and apply them.
How to do it...
Follow these steps to import and apply a design package:
- Navigate to the site in your preferred web browser.
- Select Site settings from the Settings menu.
- Select Import Design Package from the Look and Feel section.
- Select the design package to import.
- Select Import.
How it works...
Importing a design package adds the SharePoint solution file (WSP) to the Solutions Gallery of the site collection and applies the customizations it contains. 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 imported and applied with PowerShell or with code using the server-side object model.
Follow these steps to import and apply 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
- Specify the path to the design package WSP file and get the file name from the path.
$filePath = "C:\My PowerShell Design-1.0.wsp" $fileName = [System.IO.Path]::GetFileName($filePath)
- Create a
DesignPackageInfo
object to represent the design package we are about to upload. In the constructor, specify the major and minor version of the design package.$package = New-Object Microsoft.SharePoint.Publishing.DesignPackageInfo($fileName, [Guid]::Empty, 1, 0)
- Create a temporary folder in the
RootWeb
site to upload the design package to:$tempFolderName = "temp_designupload_" + ([Guid]::NewGuid).ToString() $tempFolder = $site.RootWeb.RootFolder.SubFolders.Add($tempFolderName)
- Use the
OpenRead
method ofSystem.IO.File
to read the contents of the design package WSP file and add the file to theFiles
collection of the temporary folder.$fileBinary = [System.IO.File]::OpenRead($filePath) $file = $tempFolder.Files.Add($fileName, $fileBinary, $true) $fileBinary.Close()
- Use the
Install
method ofMicrosoft.SharePoint.Publishing.DesignPackage
to add the design package to the Solutions Gallery and apply the customizations in the design package to the site collection.[Microsoft.SharePoint.Publishing.DesignPackage]::Install($site, $package, $file.Url)
- Delete the temporary folder.
$tempFolder.Delete()
- Use the
Dispose
method to discard theSPSite
object.$site.Dispose()
Follow these steps to import and apply 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)
- Specify the path to the design package WSP file and get the file name from the path.
var filePath = "C:\My Code Design-1.0.wsp"; var fileName = Path.GetFileName(filePath);
- Create a
DesignPackageInfo
object to represent the design package we are about to upload. In the constructor, specify the major and minor versions of the design package.var package = new DesignPackageInfo(fileName, Guid.Empty, 1, 0);
- Create a temporary folder in the
RootWeb
site to upload the design package to.var tempFolderName = "temp_designupload_" + Guid.NewGuid().ToString(); var tempFolder = web.RootFolder.SubFolders.Add(tempFolderName);
- Use the
OpenRead
method ofSystem.IO.File
to read the contents of the design package WSP file and add the file to theFiles
collection of the temporary folder.var fileBinary = File.OpenRead(filePath); var file = tempFolder.Files.Add(fileName, fileBinary, true); var fileBinary.Close();
- Use the
Install
method ofMicrosoft.SharePoint.Publishing.DesignPackage
to add the design package to the Solutions Gallery and apply the customizations in the design package to the site collection.DesignPackage.Install(site, package, file.Url);
- Delete the temporary folder.
tempFolder.Delete();
See also
- The SharePoint 2013 Design Manager design packages article on MSDN at http://msdn.microsoft.com/en-us/library/jj862342.aspx
- The How to: Upload a File to a SharePoint Site from a Local Folder article on MSDN at http://msdn.microsoft.com/en-us/library/ms454491(v=office.14).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