DesignPackage class

SharePoint 2013

A static class that is used to import and export a design package to and from a site collection.


Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public static class DesignPackage

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))

            // 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);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.