IT tutorials
 
Applications Server
 

Sharepoint 2013 : Understanding SharePoint app model architecture (part 6) - Working with app user-interface entry points - Building app part

1/11/2014 1:55:46 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

8. Working with app user-interface entry points

Every SharePoint app requires a start page. As you know, the URL to the start pages is used within an app launcher to redirect the user from the host web to the start page. This type of entry into the user interface of the app is known as a full immersion experience because the app takes over the user interface of the browser with a full-page view.

The user interface guidelines of SharePoint app development require the app start page to provide a link back to the host web. This requirement exists so that a user can always return to the host web from which the app has been launched. When you are developing a SharePoint-hosted app, there is a standard master page used in app webs named app.master that automatically adds the required link back to the host web for you.

When developing a cloud-based app with the start page in the remote web, you cannot rely on a SharePoint master page to automatically provide the link on the start page which redirects the user back to the host web. Instead, you must use a technique that involves reading the SPHostUrl parameter which is passed to the start page in the query string. This is one of the key reasons why you always want to follow the practice of adding the {StandardTokens} token to the start page URL of a cloud-hosted app.

There are several different techniques that you can use in the code behind a start page in the remote web to read the SPHostUrl parameter value from the query string and use it to configure the required link back to the host web. For example, you can accomplish this task with server-side C# code or with client-side JavaScript code.

In addition to the required start page, a SharePoint app can optionally provide two other types of entry points known as app parts and UI custom actions. Unlike the start page, you use app parts and UI custom actions to extend the user interface of the host web.

Building app parts

An app part is a user interface element that is surfaced on pages in the host web by using an IFrame. Once an app with an app part has been installed, a user can then add an app part to pages in the host web by using the same user interface experience that is used to add standard web parts.

You implement an app part in Visual Studio 2012 by using a client web part. This makes most developers ask, “What’s the different between an app part and a client web part?” The best way to think about this is that the term “app part” is meant for SharePoint users, whereas the term “client web part” is used by developers to describe the implementation of an app part.

Despite having similar names, client web parts are very different from the standard web parts that are familiar to most SharePoint developers. In particular, a client web part cannot have any server-side code that runs within the SharePoint host environment. The implementation of a client web part must follow the rules of SharePoint app development.

Client web parts are supported under each of the three app hosting models. You implement a client web part in a SharePoint-hosted app by using HTML, CSS, and JavaScript. In a cloud-hosted app, you also have the option of implementing the behavior for a client web part by using server-side code in the remote web.

At first, many developers assume that a client web part is nothing more than an IFrame wrapper around an external web page. However, the client web part provides significant value beyond that. When you configure the URL within a client web part, you can use the same tokens as with the start page, such as ~appWebUrl, ~remoteAppUrl, and {StandardTokens}. Client web parts also support adding custom properties, as well. Furthermore, the page behind a client web part is often passed contextual security information that allows it to call back into the SharePoint host environment with an established app identity. You can think of the client web part as an IFrame on steroids.

When you want to add a new client web part to a SharePoint app project, you use the Add New Item command. The Add New Item dialog box in Visual Studio 2012 provides a Client Web Part item template, as shown in Figure 7.

When you add a new project item for a client web part, Visual Studio 2012 adds an elements.xml file to the SharePoint app project that contains a ClientWebPart element. The following code is a simple example of the XML definition for a client web part in a SharePoint-hosted app project that is implemented by using a page inside the app web:

The Add New Item dialog provides templates for adding client web parts and UI custom actions to app projects.

Figure 7. The Add New Item dialog provides templates for adding client web parts and UI custom actions to app projects.

<ClientWebPart Name="MyAppPart" Title="My App Part" Description="My description"
DefaultWidth="300" DefaultHeight="200" >

<Content Type="html" Src="~appWebUrl/Pages/AppPart1.aspx" />

</ClientWebPart>

As you can see from this example, the content displayed in a client web part is configured by assigning a URL to the Src attribute of the <Content> element. The web page that is referenced by this URL is usually added to either the app web or to the remote web. However, you can even reference a web page on the Internet that is neither in an app web nor in a remote web. The only important restriction is that the web page cannot be returned with the X-Frame-Options header in the HTTP response. This is a header used by some websites to prevent its pages from being used inside an IFrame with a type of attack known as clickjacking.

Here is something that can catch you off guard when creating a client web part in a SharePoint-hosted app: the default behavior of SharePoint 2013 is to add the X-Frame-Options header with a value of SAMEORIGIN in the HTTP response when it serves up pages from a SharePoint site. The result of this is that a page served up from the app web will not work when you attempt to use it as the page behind a client web part. The way to deal with this problem is to add the following directive to the top of any page in the app web referenced by a client web part to suppress the default behavior of adding the X-Frame-Options header:

<WebPartPages:AllowFraming ID="AllowFraming" runat="server" />

When you develop client web parts, you can add custom properties. The real value of custom properties is that they can be tailored by the user in the browser in the same fashion as a user customizes the properties of standard web parts. You define a custom property by adding a <Properties> element into the <ClientWebPart> element and then adding a <Property> element within that, as illustrated in Example 2.

Example 2. Client Web Part properties

<Properties>
<Property
Name="MyProperty"
Type="string"
WebBrowsable="true"
WebDisplayName="My Custom Property"
WebDescription="Insightful property description"
WebCategory="Custom Properties"
DefaultValue="Some default value"
RequiresDesignerPermission="true" />
</Properties>

Once you have added a custom property, you must then modify the query string at the end of the URL that is assigned to the Src attribute in the <Content> element. You do this by adding a query string parameter and assigning a value based on a pattern by which the property name is given an underscore before it and after it. Thus, for a property named MyProperty, you should create a query string parameter and assign it a value of _MyProperty_. This would result in XML within the <Content> element that looks like the following:

<Content
Type="html"
Src="~appWebUrl/Pages/AppPart1.aspx?MyPropertyParameter=_MyProperty_"
/>

Note that you can use any name you want for the query string parameter itself. It’s when you assign a value to the parameter that you have to use actual property name and follow the pattern of adding the underscores both before and after.

 
Others
 
- Sharepoint 2013 : Understanding SharePoint app model architecture (part 5) - Setting the start page URL, Understanding the app web
- Sharepoint 2013 : Understanding SharePoint app model architecture (part 4) - Reviewing the app manifest
- Sharepoint 2013 : Understanding SharePoint app model architecture (part 3) - Understanding app hosting models
- Sharepoint 2013 : Understanding SharePoint app model architecture (part 2) - Understanding app code isolation
- Sharepoint 2013 : Understanding SharePoint app model architecture (part 1) - Working with app service applications
- Sharepoint 2013 : Introducing SharePoint Apps - Understanding the new SharePoint app model
- Exchange Server 2013 : Extending Exchange - Choosing the Right API for Exchange Development in Exchange 2013
- Exchange Server 2013 : Extending Exchange - Accessing Exchange Programmatically
- Active Directory 2008 : Configuring Active Directory Certificate Services (part 4) - Configuring Additional CA Server Settings
- Active Directory 2008 : Configuring Active Directory Certificate Services (part 3) - Revoking Certificates
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us