DesignPackage class
A static class that is used to import and export a design package to and from a site collection.
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Publishing.DesignPackage
Namespace: Microsoft.SharePoint.Publishing
Assembly: Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)
Syntax
'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class DesignPackage
'Usage
You do not need to declare an instance of a static class in order to access its members.
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public static class DesignPackage
Examples
The following example demonstrates how to export a design package from a source site collection and install it into another site collection.
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
namespace PackagingSample
{
class Program
{
const string srcSiteUrl = "http://<Server>/sites/<SourceSiteURL>";
const string dstSiteUrl = "http://<Server>/sites/<DestinationSiteURL>";
const string packageName = "MyPackage"; // null to use the default name
static void Main(string[] args)
{
// Export a package from source site collection
SPSite srcSite = new SPSite(srcSiteUrl);
DesignPackageInfo info = DesignPackage.Export(srcSite, packageName, false);
// The package is exported to the solution gallery with the name format <PackageName>-<MajorVersion>.<MinorVersion>
string packageFileName = string.Format("{0}-{1}.{2}.wsp", info.PackageName, info.MajorVersion, info.MinorVersion);
// Download the exported package from the solution gallery
SPFile file = srcSite.RootWeb.GetFile(srcSiteUrl + "/_catalogs/solutions/" + packageFileName);
using (Stream fileStream = file.OpenBinaryStream())
{
using (Stream packageFileStream = File.Create(@"C:\" + packageFileName))
{
fileStream.CopyTo(packageFileStream);
}
}
srcSite.Dispose();
// Import the package into another site collection
SPSite dstSite = new SPSite(dstSiteUrl);
using (Stream fileStream = File.Open(@"C:\" + packageFileName, FileMode.Open))
{
SPFile packageFile = dstSite.RootWeb.GetFolder(dstSiteUrl + "/Documents").Files.Add(packageFileName, fileStream);
DesignPackage.Install(dstSite, info, packageFile.Url);
DesignPackage.Apply(dstSite, info);
}
dstSite.Dispose();
}
}
}
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.