Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Cleanup pass for tables, lists, whitespace, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
roharp committed May 23, 2016
1 parent e8ff306 commit 5ba12d8
Show file tree
Hide file tree
Showing 94 changed files with 327 additions and 1,934 deletions.
19 changes: 3 additions & 16 deletions articles/Add-a-custom-ribbon-to-your-SharePoint-site.md
@@ -1,15 +1,14 @@

# Add a custom ribbon to your SharePoint site

Add or remove a custom ribbon on your SharePoint site. Add JavaScript event handlers using the embed JavaScript technique to handle your custom ribbon's events.

_**Applies to:** add-ins for SharePoint | SharePoint 2013 | SharePoint Online_
_**Applies to:** add-ins for SharePoint | SharePoint 2013 | SharePoint Online_

The [Core.RibbonCommands](https://github.com/OfficeDev/PnP/tree/master/Samples/Core.RibbonCommands) code sample shows you how to add a custom ribbon to a SharePoint site. Use this solution if you want to:

- Add a custom ribbon, group, or button to your SharePoint site or list.

- Display a custom ribbon for specific content types, sites, or lists.


**Note** This code sample shows how to call the JavaScript functions that handle events raised by the ribbon's buttons. This code sample does not provide the implementation of the JavaScript event handler functions for the ribbon's buttons. To implement the JavaScript event handler functions, use the embed JavaScript technique to embed the JavaScript event handler functions on all pages where your custom ribbon appears. For more information about embedding JavaScript, see [Customize your SharePoint site UI by using JavaScript](Customize-your-SharePoint-site-UI-by-using-JavaScript.md).

Expand All @@ -18,7 +17,6 @@ The [Core.RibbonCommands](https://github.com/OfficeDev/PnP/tree/master/Samples/

To get started, download the [Core.RibbonCommands](https://github.com/OfficeDev/PnP/tree/master/Samples/Core.RibbonCommands) sample add-in from the [Office 365 Developer patterns and practices](https://github.com/OfficeDev/PnP/tree/dev) project on GitHub.


## Using the Core.RibbonCommands app
<a name="sectionSection1"> </a>

Expand All @@ -28,12 +26,8 @@ This code sample defines a custom ribbon by using Models\RibbonCommands.xml. Rib

The custom ribbon displays on all sites and lists on the host web because **RegistrationId="0x01"** and **RegistrationType="ContentType"**. **RegistrationId="0x01"** and **RegistrationType="ContentType"** specify that the ribbon will appear for all content types that inherit from type **"0x01"**, which are content types that inherit from the **Item** class. To apply your ribbon to a custom content type, replace "0x01" with your custom content type's ID. To apply your ribbon to a list, change the value of RegistrationType to **List**.


**Note** The code in this article is provided as-is, without warranty of any kind, either express or implied, including any implied warranties of fitness for a particular purpose, merchantability, or non-infringement.




```XML
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
Expand Down Expand Up @@ -238,11 +232,9 @@ The custom ribbon displays on all sites and lists on the host web because **Reg
</Elements>
```


**Note** If you use the embed JavaScript technique to implement event handling for your ribbons' buttons, your JavaScript file must implement the methods defined in the **CommandUIHandler** elements. For example, your embedded JavaScript file should implement functions like **GetCurrentItem** and **AddNewCustom**.

**InitializeButton_Click** in Default.aspx performs the following tasks:

**InitializeButton_Click** in Default.aspx performs the following tasks:

1. Calls **GetCustomActionXmlNode** to read the XML file and return the **CustomAction** object defined in RibbonCommands.xml. The **CustomAction** object contains the ribbon customization markup.

Expand All @@ -255,9 +247,6 @@ The custom ribbon displays on all sites and lists on the host web because **Reg
5. Adds the ribbon customization markup (in **xmlContent**) to the SharePoint site using the **CustomAction.CommandUIExtension**.

6. Registers the custom ribbon by setting the **CustomAction.RegistrationId** and **CustomAction.RegistrationType** to the attribute values of the **CustomAction** object read in step 2.




```C#
protected void InitializeButton_Click(object sender, EventArgs e) {
Expand Down Expand Up @@ -306,11 +295,9 @@ The custom ribbon displays on all sites and lists on the host web because **Reg
}
```


## Additional resources
<a name="bk_addresources"> </a>


- [Office 365 development patterns and practices solution guidance](Office-365-development-patterns-and-practices-solution-guidance.md)

- [Customize your SharePoint site UI by using JavaScript](Customize-your-SharePoint-site-UI-by-using-JavaScript.md)
Expand Down
109 changes: 32 additions & 77 deletions articles/Autotagging-sample-app-for-SharePoint.md
@@ -1,11 +1,8 @@

# Autotagging sample add-in for SharePoint
As part of your Enterprise Content Management (ECM) strategy, you can automatically tag documents with metadata when they are created or uploaded to SharePoint.


_**Applies to:** Office 365 | SharePoint 2013 | SharePoint Online_

As part of your Enterprise Content Management (ECM) strategy, you can automatically tag documents with metadata when they are created or uploaded to SharePoint.

_**Applies to:** Office 365 | SharePoint 2013 | SharePoint Online_

The [ECM.AutoTagging](https://github.com/OfficeDev/PnP/tree/master/Samples/ECM.AutoTagging) sample shows you how to use a provider-hosted add-in to automatically tag content added to a SharePoint library with data sourced from a custom user profile property. This add-in uses remote event receivers, hosted on an Azure Web Site, to:

Expand All @@ -25,105 +22,90 @@ Use this solution if you want to:

- Modernize your code before migrating to a newer version of SharePoint, and you've used event receivers in the past.


## Before you begin
<a name="sectionSection0"> </a>

To get started, download the [ECM.AutoTagging](https://github.com/OfficeDev/PnP/tree/master/Samples/ECM.AutoTagging) sample add-in from the [Office 365 Developer patterns and practices](https://github.com/OfficeDev/PnP/tree/dev) project on GitHub.

Before you run this add-in , do the following:


1. Create an Azure Web Site and deploy the ECM.AutoTaggingWeb project to it.

2. Register your add-in using the Appregnew.aspx page in Office 365.

3. This add-in uses app-only permissions. You need to assign app-only permissions using the AppInv.aspx page in Office 365. Copy the following XML from the AppManifest.xml file to the Permission Request XML textbox on the AppInv.aspx page, as shown in Figure 1.

```
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/taxonomy" Right="Read" />
<AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read" />
</AppPermissionRequests>
```

**Figure 1. Assigning app-only permissions by using the AppInv.aspx page in Office 365**

![Screenshot of the AppInv.aspx page, with the App ID and Permission Request XML boxes highlighted](media/d733e2b0-55f3-4aee-872b-49e7e2baf470.png)

4 - In the ECM.AutoTaggingWeb project, in the ReceiverHelper.cs file, in the **CreateEventReciever** method, update the **ReceiverUrl** property with the URL of your Azure Web Site.

```C#
public static EventReceiverDefinitionCreationInformation CreateEventReciever(string receiverName, EventReceiverType type)
{

EventReceiverDefinitionCreationInformation _rer = new EventReceiverDefinitionCreationInformation();
_rer.EventType = type;
_rer.ReceiverName = receiverName;
_rer.ReceiverClass = "ECM.AutoTaggingWeb.Services.AutoTaggingService";
_rer.ReceiverUrl = "https://<Your domain>.azurewebsites.net/Services/AutoTaggingService.svc";
_rer.Synchronization = EventReceiverSynchronization.Synchronous;
return _rer;
}

```

5 - Package and deploy your add-in .
```
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/taxonomy" Right="Read" />
<AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read" />
</AppPermissionRequests>
```

**Figure 1. Assigning app-only permissions by using the AppInv.aspx page in Office 365**

![Screenshot of the AppInv.aspx page, with the App ID and Permission Request XML boxes highlighted](media/d733e2b0-55f3-4aee-872b-49e7e2baf470.png)

4. In the ECM.AutoTaggingWeb project, in the ReceiverHelper.cs file, in the **CreateEventReciever** method, update the **ReceiverUrl** property with the URL of your Azure Web Site.

```C#
public static EventReceiverDefinitionCreationInformation CreateEventReciever(string receiverName, EventReceiverType type)
{

EventReceiverDefinitionCreationInformation _rer = new EventReceiverDefinitionCreationInformation();
_rer.EventType = type;
_rer.ReceiverName = receiverName;
_rer.ReceiverClass = "ECM.AutoTaggingWeb.Services.AutoTaggingService";
_rer.ReceiverUrl = "https://<Your domain>.azurewebsites.net/Services/AutoTaggingService.svc";
_rer.Synchronization = EventReceiverSynchronization.Synchronous;
return _rer;
}

```
5. Package and deploy your add-in .

When you start the add-in , the start page of the Document Autotagging provider-hosted add-in displays, as shown in Figure 2. The start page shows some additional configuration steps you need to perform before you assign or remove the event receivers.


**Figure 2. Additional configuration steps to be performed on the add-in start page in SharePoint**

![Screenshot of the autotagging add-in start page, with three setup steps highlighted.](media/eb0521b2-11e2-4c57-8026-d7e838c21eae.png)


## Using the ECM.Autotagging sample add-in
<a name="sectionSection1"> </a>

This sample uses a remote event receiver to automatically tag (add metadata to) documents that are added to a document library, with data from a custom user profile property. The process flow for autotagging documents using the remote event receiver is shown in Figure 3.


**Figure 3. Process flow for tagging documents in a document library by using a remote event receiver**

![An illustration of the process for tagging a document in a library. When the user creates content, the add-in contacts the event receiver, which accesses the user's profile and submits information to SharePoint.](media/430eee99-5ab9-49d8-8021-71d7cee79a73.png)

To assign metadata to the newly created document in the document library by using a remote event receiver:



1. A user creates or uploads new content to a document library. A remote event receiver is assigned to handle **ItemAdding** or **ItemAdded** events on this document library.

2. The **ItemAdding** or **ItemAdded** method makes a call to the remove event receiver.

3. The provider-hosted add-in fetches the value of a custom user profile property in the User Profile Service of SharePoint for that user. In this sample add-in , the Classification custom user profile property that was added previously is retrieved.

4. The remote event receiver updates the metadata on the new document with the value of the custom user profile property for that user.


### Run Scenario 1

When you choose the button **Run Scenario 1**, the add-in does the following:


1. Creates a document library.

2. Creates the remote event receiver for the ItemAdding event.

**Note** This article discusses the ItemAdding event receiver type. Generally, the ItemAdding event receiver type performs better than the ItemAdded event receiver type. The ECM.Autotagging sample provides code for both the ItemAdding and ItemAdded event receiver types.

3. Adds the remote event receiver to the document library.

The following code, in the **btnScenario1_Click** method of the Default.aspx.cs page in the ECM.AutoTaggingWeb project, shows these steps.


**Note** The code in this article is provided as-is, without warranty of any kind, either express or implied, including any implied warranties of fitness for a particular purpose, merchantability, or non-infringement.




```C#
protected void btnScenario1_Click(object sender, EventArgs e)
{
Expand All @@ -149,18 +131,10 @@ protected void btnScenario1_Click(object sender, EventArgs e)
}
}
}





```

A call is made to the **CreateContosoDocumentLibrary** method. The following code in the ScenarioHandler.cs file uses methods from OfficeDevPnP.Core to create a custom document library with a custom content type. The default content type in the document library is removed.




```C#
public void CreateContosoDocumentLibrary(ClientContext ctx, Library library)
{
Expand Down Expand Up @@ -229,16 +203,12 @@ private void CreateLibrary(ClientContext ctx, Library library, string associateC

After this code runs, the AutoTaggingSampleItemAdding document library is created in Site Contents, as shown in Figure 4.


**Figure 4. AutoTaggingSampleItemAdding document library**

![Screenshot shwoing the Site Contents page with the new AutoTaggingSampleItemAdd document library.](media/8820a44f-8df8-4c80-aeaa-e50c37b8912c.png)

In the ECM.AutoTaggingWeb project, in the ReceiverHelper.cs file, the **CreateEventReciever** method creates the ItemAdding event receiver definition. In the ECM.AutoTaggingWeb project, the Services folder includes a web service called AutoTaggingService.svc. When you published the ECM.AutoTaggingWeb project to your Azure Web Site, this web service was also deployed to your site. The **CreateEventReciever** method assigns this web service as the remote event receiver on the document library. The following code from the **CreateEventReciever** method shows how to assign the web service to the remote event receiver.




```C#
public static EventReceiverDefinitionCreationInformation CreateEventReciever(string receiverName, EventReceiverType type)
{
Expand All @@ -256,9 +226,6 @@ public static EventReceiverDefinitionCreationInformation CreateEventReciever(str

The following code from the **AddEventReceiver** method assigns the remote event receiver to the document library.




```C#
public static void AddEventReceiver(ClientContext ctx, List list, EventReceiverDefinitionCreationInformation eventReceiverInfo)
{
Expand All @@ -283,9 +250,6 @@ Now, the remote event receiver is added to the document library. When you upload

The **HandleAutoTaggingItemAdding** method, in the AutoTaggingService.svc.cs file, uses the **GetProfilePropertyFor** method to retrieve the value of the Classification user profile property.




```C#
public void HandleAutoTaggingItemAdding(SPRemoteEventProperties properties,SPRemoteEventResult result)
{
Expand All @@ -310,14 +274,9 @@ public void HandleAutoTaggingItemAdding(SPRemoteEventProperties properties,SPRem
}

```



**Important** After retrieving the **Classification** value from the **GetProfilePropertyFor** method, the **Classification** value must be formatted in a certain way before it can be stored as metadata on the document. The **GetTaxonomyFormat** method in the AutoTaggingHelper.cs file shows how to format the **Classification** value.




```C#
public static string GetTaxonomyFormat(ClientContext ctx, string term)
{
Expand Down Expand Up @@ -352,12 +311,10 @@ public static string GetTaxonomyFormat(ClientContext ctx, string term)

```


### Remove Event Scenario 1

When you choose the button **Remove Event Scenario 1**, the following code runs to remove the event receiver from the document library.


```C#
public static void RemoveEventReceiver(ClientContext ctx, List list, string receiverName)
{
Expand All @@ -374,11 +331,9 @@ public static void RemoveEventReceiver(ClientContext ctx, List list, string rece

```


## Additional resources
<a name="bk_addresources"> </a>


- [Enterprise Content Management solutions for SharePoint 2013 and SharePoint Online](Enterprise-Content-Management-solutions-for-SharePoint-2013-and-SharePoint-Online.md)

- [OfficeDevPnP.Core sample](https://github.com/OfficeDev/PnP-Sites-Core/tree/master/Core)
Expand Down

0 comments on commit 5ba12d8

Please sign in to comment.