6. Applications for SharePoint
The new SharePoint app model brings
along with it new experiences for developing for SharePoint. The
primary difference is more reliance on web-based technologies such as
JavaScript. Luckily with Visual Studio there have been enhancements to
the JavaScript IntelliSense features to make it a more fluid
development experience. There are new Visual Studio templates for
supporting the app model, as well as a Project Layout and Packaging
framework. All apps for SharePoint can be developed within Visual
Studio, but you need a developer site to run and debug the apps, as
shown in Figure 3.
SharePoint Solutions Project and Item Type Templates
The new Project Type templates needed
for supporting apps is straightforward, with only a single project type
needed for the SharePoint apps that you will build (see Table 1).
After you create the project, you can build any of the specific app
designs based on what the functionality of your app needs (see Table 2).
TABLE 1: App Project Type Templates
NAME |
DESCRIPTION |
App for SharePoint 2013 |
The project type enables developers to
create apps built for SharePoint and include the ability to choose the
hosting type and UX experience. |
App for Office 2013 |
The project type is used to create apps inside of Office 2013 to provide additional content and functionality. |
TABLE 2: App Item Type Templates
NAME |
DESCRIPTION |
List |
This template now provides the ability to create a list with a custom set of fields or create a new list from an existing list. |
Remote Event Receiver |
This template enables you to create a remote event receiver to handle SharePoint events using a remote service. |
Content Type |
This template provides a wizard for creating a content type item with a reusable collection of fields. |
Workflow |
This template provides a wizard that
enables you to create SharePoint 2013 workflows that can be based on a
list or site in Visual Studio. |
Empty Element |
This template creates an elements.xml
file that enables you to define SharePoint artifacts using XML. The
most common usage would be defining a field in your SharePoint project. |
Site Column |
This template creates the elements.xml
file and default field attributes for the custom site columns that can
be used in the fields or content types. |
Module |
This template creates a simple module file with a sample text file showing how to deploy files. |
Client Web Part (Host Web) |
This template creates the elements.xml needed to host an app for SharePoint inside of a web part called a Client Web Part. |
UI Custom Action (Host Web) |
This template creates the elements.xml
needed to create a SharePoint custom action that links to an app for
SharePoint as the resulting URL action. |
Task Pane App |
This template provides a wizard for
creating an app for Office 2013 with the Task Pane option selected and
the available Office applications selectable. |
Content App |
This template creates an app for Office 2013 for building out content that appears in the body of the Office documents. |
Files and Project Layout
The new SharePoint App template in
Visual Studio creates the solution with the project, project items, and
files needed to get started. The basic code with all the required
properties are set up with the wizard. The files created will be based
on the type of hosting model you select for the apps for SharePoint.
The cloud-hosted apps with either the Auto-Hosted
or Provider-Hosted apps have the same folder and files structure. The
difference between the two is how Visual Studio handles packaging,
deploying, and debugging the apps based on where they are hosted. The
projects contain an App Project and a Web Application Project. The App
Project contains the app-specific files, whereas the Web Application
Project contains the files needed to host the app. The following files
are required for the app projects:
- AppIcon.png — This image is the one used to display on the homepage.
- AppManifest.xml — This file contains the app elements just like the elements and feature .xml files in SharePoint Solutions.
The Web Application Project contains a specific
file called the TokenHelper file that enables your app to make secure
access calls into SharePoint resources. This is accomplished by using
the access tokens defined per application and stored within the app.
The other files are all standard web files with the app
framework built into them, such as the ClientID and ClientSecret values
stored in the Web.config file.
The SharePoint-hosted apps provide a slightly
different layout because the packaging for a SharePoint Solution is
needed in addition to the app components. Also, these projects are
hosted within SharePoint and do not need a separate web application
because SharePoint is a web application. If you are familiar with
traditional SharePoint Solutions, you can quickly see that this
solution is similar to those in SharePoint 2010 and that the project
layout is similar with Features, Packages, and HTML folders. Because
this is still an app, you still need the AppManifest.xml file that will
be created for you from the Project template.
Depending on the type of project you are working
with, either the App Project or the Web Application Project, you can
set the required project properties from the Properties window, and you
can use the built-in designers for any support tool such as the
AppManifest.xml Editor, Feature Editor, and SharePoint Packaging
Editor. Figure 4 shows the Autohosted app with the App properties and AppManifest.xml Editor opened.
Packaging
A new packaging framework is used
specifically for apps based on the Open Packaging Conventions (OPC).
This new packaging format is what enables apps to be hosted outside of
SharePoint and even integrated into Microsoft Office. Each app for
SharePoint package has the extension of .app. The file that drives all
the supporting app files is the AppManifest.xml file, which contains
the properties and links to other files. This file is required in an
app to allow it to be packaged correctly. In addition to the required
app files, there could also be other packages for SharePoint (WSP),
Resource files (RESX), Data Tier Application Packages (DACPACs), and
Web Deploy Packages.
NOTE The
.app packaging format, which is based on the Microsoft Office format,
is essentially .zip files. To view the contents of an app, just rename
the file extension to .zip, and you can view it in Windows Explorer.
To complete the packaging, you need to decide
where you will publish your app to for other users to consume. There
are two places that you can publish your packages to:
- The public Office Store — This enables other users to view and download your app.
- An internal organization app catalog — This option enables you to create internal organization apps for users of your internal deployment.
There is a new Publish Office apps Wizard that
can guide you through final packaging of your app for SharePoint for
publishing. This wizard walks you through the process and asks
different questions based on the type of app for SharePoint you have
selected. During this process you must provide the identity of your app
with the client ID and the client secret that was found in the
web.config. After you work through the wizard, Visual Studio
automatically generates the files needed to publish your app. To see
these files you can navigate to the <app>\bin\Debug\app.publish
folder in your project. All apps contain the .app file, which can be
uploaded to the right catalog for deployment. If there is also a Web
Application Project, Visual Studio generates a few files in addition to
the required web application files that are stored in a .zip file in
the same directory that are used during Web Deploy:
- ProjectName.deploy.cmd — The batch commands used to deploy your package.
- ProjectName.SetParameters.xml — The parameters used in the deploy.cmd file.
- ProjectName.SourceManifest.xml — Provides the files and layout of the package used only when creating the package itself.
Apps for Office
These apps are critical for
business apps because they work in both Office Applications and Office
Web Applications. This enables apps for Office to run inside of
SharePoint 2013 without any changes. These apps are built with the same
concept of portability and use standard web technologies such as HTML,
CSS, REST, JavaScript, and more. Currently, the supported Office Web
Applications that are supported are Excel and Outlook; although the
Rich Office Application also supports Word and Project. Other Office
Applications will be supported in the future as well as enhancements to
current applications. These apps are displayed using the IE9 add-in, so
all HTML 5 is supported just like the browser.