Silverlight Web Part
Beyond the Standard and Visual Web
Parts, you can also use the Silverlight Web Part. The Silverlight Web
Part provides a way to deploy rich media applications to SharePoint.
The Silverlight Web Part combines a Web Part and Silverlight
application into one project (so it uses the Web Part infrastructure to
deploy the Silverlight application) that it then deploys to SharePoint.
Behind the scenes, the Web Part represents a container that points to a
Silverlight application that it deploys to SharePoint. Similar to the
Visual Web Part, you can use a designer experience to build rich Web
Parts (also ones that can leverage the CSOM API to interact with
SharePoint data). Use the Silverlight Web Part for rich media
applications, data-bound applications, and applications that you want
to use across all versions of SharePoint.
Figure 7 shows a simple Silverlight Web Part that has been deployed to SharePoint.
2.3 Creating SharePoint-Hosted Apps
SharePoint-hosted apps are a newer
breed of app in SharePoint 2013 and are generally a good fit across
many developers’ needs. This is because many SharePoint applications
can be lightweight in nature, they leverage only client-side code, and
they don’t require heavy back-end processing elements.
SharePoint-hosted apps are by far the easiest app to create and deploy;
the contents of the app are deployed to a single SharePoint site.
A number of different elements can make up a SharePoint-hosted app. For example, in Figure 8 note the range of available options, such as Content Type, Workflow, or even App for Office.
Another reason that SharePoint-hosted apps are
popular is that you can create some of the more common SharePoint
artifacts you use on a regular basis; that is, lists, content types,
and site columns, and then deploy them to a cloud-hosted or on-premises
instance of SharePoint.
Lists are a core part of SharePoint and have a
rich object model that you can use to code against them. As a potential
part of lists, site columns are reusable column definitions that you
can create and then repurpose across the SharePoint site. For example,
if you need a very specific site column called Tax Rate that has a
calculation embedded within it, you can use that site column to enforce
some level of consistency across your lists and sites. Content types
are also a reusable object that you can repurpose across your
SharePoint site. Content types can come in different shapes and sizes;
for example, you might define a content type as a set of columns or as
a custom document template. One common use of content types is for
custom documents (for example, a legal contract with boilerplate
text).You create the content type and bind that content type to a
document library. You can create site columns, content types, and lists
in a variety of ways. For example, you can create each one of these
objects through the SharePoint Web interface. You can also leverage
SharePoint Designer to create all of these objects or even Visual
Studio to create content types and list definitions. Using Visual
Studio makes it possible to begin integrating list definitions into
other applications or redeploying a custom list definition across
multiple SharePoint sites.
In the following Try It Out you take a look at how to use Visual Studio to build custom site columns for lists.
TRY IT OUT: Creating a Site Column Using Visual Studio 2012
The project templates in Visual Studio
2012 make it convenient for you to create site columns, content types,
and lists. To create a custom site column using Visual Studio:
1. Open Visual Studio 2012, click File ⇒ New, and then click Project.
2. Select the Empty SharePoint Project in the SharePoint 2013 project node. Provide a name for the project (SPH_Sales) and click OK.
3. In the
project creation wizard, make sure your SharePoint site is typed in
correctly and then select the farm-level solution for the level of
trust. Click Finish.
4. Visual
Studio creates an empty SharePoint project for you. When it’s done,
right-click the top-level project node and select Add ⇒ New Item.
5. Select the Site Column template and provide a name for the file (Sales) and click Add — see Figure 9.
6. Add the following bolded code to the Elements.xml file that is created in the default project.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{4c3a41d4-366d-44c7-910c-74716019ae75}"
Name="Sales"
DisplayName="Sales"
Type="Choice"
Required="FALSE"
Group="Sales Levels">
<CHOICES>
<CHOICE>Premier</CHOICE>
<CHOICE>Gold</CHOICE>
<CHOICE>Silver</CHOICE>
<CHOICE>Bronze</CHOICE>
<CHOICE>Non-Affiliated</CHOICE>
</CHOICES>
<Default>Bronze</Default>
</Field>
</Elements>
7. Press F6 to
build the project. When the project successfully builds, click Build
and then Deploy to deploy the site column to SharePoint.
8. Navigate to
your SharePoint site and click Site Actions ⇒ Site Settings. Under
Galleries, click Site Columns. You should now see a Customers group
with a Sales Levels site column — see Figure 10.
9. Click the Sales site column to see the details of the column, shown in Figure 11.
10. Navigate to the top-level SharePoint site, click Add an App and create a new Custom List called Sales.
11. Click the List tab and then select List Settings.
12. Click the Add from site columns link.
13. In the Groups drop-down menu, select Sales Level and then select Sales Type. Click Add, as shown in Figure 12.
14. Click OK to add the new site column you created to the list.
15. Add a new item to the Sales list. You’ll now see an option with the new site column, as shown in Figure 13.
16. Your newly amended list should now look similar to Figure 14.
How It Works
A column is the constituent part of a
list and is composed of one or more items. You create and store site
columns at the site level, and thus you can reuse them across your
SharePoint site. In this example, you created a site column and added
it to the Sales list. You could also leverage this type of column in
other lists across your site — thus making it a primary distinguishing
factor across the normal and site columns.
Although you can create lists manually through
the browser or in SharePoint Designer, you might have the need to
create a site column, list definition, or content type using Visual
Studio (for example, you want to package and distribute a content type
with a larger solution). Using the out-of-the-box project templates,
these objects are much easier to create than in past versions of
SharePoint. When you do create objects such as site columns, list
definitions, or content types using Visual Studio, you need to be
familiar with the Collaborative Application Markup Language (CAML)
syntax and structure for the objects you’re trying to create (CAML is
an XML syntax specific to SharePoint). For example, the following XML
defines a site column that you can deploy to a SharePoint site and then
reuse across the site. The site column defines a reusable list of Sales
types for a program a company is running; it does this through the XML
definition of the site column.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{4c3a41d4-366d-44c7-910c-74716019ae75}"
Type= "Choice"
FillInChoice="TRUE"
Name="Sales"
DisplayName="Sales"
Group="Sales Levels">
<CHOICES>
<CHOICE>Premier</CHOICE>
<CHOICE>Gold</CHOICE>
<CHOICE>Silver</CHOICE>
<CHOICE>Bronze</CHOICE>
<CHOICE>Non-Affiliated</CHOICE>
</CHOICES>
<Default>Bronze</Default>
</Field>
</Elements>
You can create a site column manually in
SharePoint Designer or in Visual Studio. In this exercise, you used
Visual Studio, which treats the site column like any other SharePoint
project; it creates a feature and
then deploys the XML elements file (which represents the definition of
the site column) to the appropriate place within SharePoint.