How to package an application in SharePoint 2013

Source: Internet
Author: User

O is actually quite simple and ugly.

The application in SharePoint 2013 is actually a compressed package based on openxml. You can change the Suffix from app to zip, and then you can see the structure in it.

There are three main files: appmanifest.xml?appicon.png=appicon.png. config. xml. Through openxml tools, you can also view the relationships between them ).

Then it's easy. First create an appdefinition class that can be serialized into XML format (the class here is the simplest, that is, it does not contain permissions and other information ). If you want to be more professional, you can generate an appdefinition Class Based on XML schema definition (XSD) in SharePoint app manifest (schema map) for serialization.

[XmlRoot("App", Namespace = "")]public class AppDefinition {    [XmlAttribute("Name")]    public string Name { get; set; }    [XmlAttribute("ProductID")]    public string ProductID { get; set; }    [XmlAttribute("Version")]    public string Version { get; set; }    [XmlAttribute("SharePointMinVersion")]    public string SharePointMinVersion { get; set; }    [XmlElement]    public AppProperties Properties { get; set; }        [XmlElement(ElementName = "AppPrincipal")]    public AppPrincipal Principal { get; set; }        [XmlRoot]    public class AppProperties {        [XmlElement]        public string Title { get; set; }        [XmlElement]        public string StartPage { get; set; }    }    [XmlRoot]    public class AppPrincipal {        [XmlElement]        public RemoteWebApplication RemoteWebApplication { get; set; }    }    [XmlRoot]    public class RemoteWebApplication {        [XmlAttribute("ClientId")]        public string ClientId { get; set; }    }}

Then, xmlserializer can be used to serialize the instantiated appdefinition (Definition) to appmanifest. xml.

AppDefinition definition = new AppDefinition() {    Name = Guid.NewGuid().ToString(),    ProductID = Guid.NewGuid().ToString("B"),    Version = "",    SharePointMinVersion = "",    Properties = new AppDefinition.AppProperties() {        Title = title,        StartPage = launchUrl    },    Principal = new AppDefinition.AppPrincipal {        RemoteWebApplication = new AppDefinition.RemoteWebApplication {            ClientId = Guid.NewGuid().ToString("B"),        }    }};
using (XmlWriter writer = XmlTextWriter.Create(partStream, new XmlWriterSettings() { Encoding = Encoding.UTF8, Indent = true })) {    XmlSerializer serializer = new XmlSerializer(typeof(AppDefinition));    serializer.Serialize(writer, definition);}

Finally, use the package class under system. Io. packaging to package.

using (Package package = Package.Open(stream, FileMode.Create)) {    PackagePart manifestPart = package.CreatePart<AppDefinition>(new Uri("/AppManifest.xml", UriKind.Relative), "text/xml", definition);    PackagePart iconPart = package.CreatePart<string>(new Uri("/AppIcon.png", UriKind.Relative), "application/wsp", path);    PackagePart configPart = package.CreatePart<AppPartConfig>(new Uri("/AppIcon.png.config.xml", UriKind.Relative), "text/xml", config);    package.CreateRelationship(manifestPart.Uri, TargetMode.Internal,        "");    manifestPart.CreateRelationship(iconPart.Uri, TargetMode.Internal,        "");    iconPart.CreateRelationship(configPart.Uri, TargetMode.Internal,        "");}

O (distinct _ distinct) O ~~ If you can understand and use it, take it for fun. Download the sample code here.


Using e the app manifest and the package of an app for Sharepoint

How to package an application in SharePoint 2013

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.