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.
Follow these steps to import and apply a design package:
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.
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:
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")
Get-SPSite
Cmdlet.$site = Get-SPSite http://sharepoint/sitecollection
$filePath = "C:My PowerShell Design-1.0.wsp" $fileName = [System.IO.Path]::GetFileName($filePath)
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)
RootWeb
site to upload the design package to:$tempFolderName = "temp_designupload_" + ([Guid]::NewGuid).ToString() $tempFolder = $site.RootWeb.RootFolder.SubFolders.Add($tempFolderName)
OpenRead
method of System.IO.File
to read the contents of the design package WSP file and add the file to the Files
collection of the temporary folder.$fileBinary = [System.IO.File]::OpenRead($filePath) $file = $tempFolder.Files.Add($fileName, $fileBinary, $true) $fileBinary.Close()
Install
method of Microsoft.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)
$tempFolder.Delete()
Dispose
method to discard the SPSite
object.$site.Dispose()
Follow these steps to import and apply a design package with code using the server-side object model:
using
statement.using (var site = new SPSite("http://sharepoint/sitecollection"))
using
statement.using (var web = site.RootWeb)
var filePath = "C:My Code Design-1.0.wsp"; var fileName = Path.GetFileName(filePath);
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);
RootWeb
site to upload the design package to.var tempFolderName = "temp_designupload_" + Guid.NewGuid().ToString(); var tempFolder = web.RootFolder.SubFolders.Add(tempFolderName);
OpenRead
method of System.IO.File
to read the contents of the design package WSP file and add the file to the Files
collection of the temporary folder.var fileBinary = File.OpenRead(filePath); var file = tempFolder.Files.Add(fileName, fileBinary, true); var fileBinary.Close();
Install
method of Microsoft.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);
tempFolder.Delete();
18.188.37.136