Sunday, 17 June 2018

How To Upgrade The App In SharePoint Online

  • Ensure that you have changed the version for the app in app manifest file

    SharePoint
  • Then upload the .app file in app catalog 
When you upload the app again in appcatalog you will get the popup window like below, on pop up click the replace it button.

SharePoint

Once you complete the above steps, then follow the below listed steps to upgrade the app in SharePoint online site
Step 1
Go to your SharePoint site where you need to upgrade the app

SharePoint

Step 2
Go to site contents page using gear menu or left navigation as shown below

SharePoint

Step 3
On the site contents page you can see the app which is installed already,

SharePoint

Step 4
Then click on ellipse (…) to view the details of the app, on the pop-up click about as shown below

SharePoint

Step 5
On the about page we have the “GET IT” button, click the button to upgrade the app

SharePoint

Step 6
After you click “GET IT”, you will get the pop-up like below, then click “Trust it” to update the app,

SharePoint

Finally SharePoint hosted app will be updated on your site with the new version.

SharePoint

Upload App file In SharePoint

In SharePoint Online we can deploy the app directly to the developer site using Visual studio, but we need to add the app in app catalog for installing the app in Team site, Project site, community site, etc.

Steps:

Follow the below steps to upload a .app file in app catalog.

Step 1:

Go the admin Portal in your SharePoint Online Tenant.



Step 2:


From Left navigation click on the “apps” to go to app catalog


Step 3: 

On the Apps page select the “App Catalog”.



Step 4: 

Then you will be navigated to the app catalog site. 

Note

If you haven’t created the app catalog site before, it will ask you to create new app catalog. Provide the app catalog name and on clicking ok the app catalog site will be created.


Step 5: 

Then click on the “Apps for SharePoint” from the left navigation.


Step 6: 

On the “AppCatalog” library you can upload the file using upload option. 



Step 7: 


Once you choose the file click ok to upload the file,



Finally your app will be successfully uploaded in app catalog library.

Saturday, 16 June 2018

Deploy SharePoint Remote Event Receiver To Microsoft Azure

Remote Event Receiver

A remote event receiver is a web service added to a web application to handle the remote events as specified. Just like the traditional event receiver, the remote event receiver works in the SharePoint as same. With a synchronous or an asynchronous event handler, the event can be triggered on the SharePoint site. And a web service calls the server-side code wherever it is deployed. The Server-side code for apps can be installed by any web server in on-premise or online.
In this article, we will discuss the deployment process of the Remote Event Receiver to Microsoft Azure, and the installation process of the client app to SharePoint site. The step by step procedure with the relative figure is given below.
Steps to deploy Remote Event Receiver to Azure
  1. First, we have to register the client app in the selected site (from where the event receiver will be triggered) and generate the client app authentication.
  2. Go to the following address, ~sitecollection /_layouts/15/appregnew.aspx. Then we will get the following window.

    Azure
    Fig: App Information
  3. Click the button generated beside the Client Id to generate the client id, as shown in position 1 and same for client secret at position 2.
  4. Provide your app with a name of your choice.
  5. Provide the Azure App Service URL which the app service has already created to host this event receiver. Copy the App domain as shown (below) in the “Fig: Azure App Service Overview Window” at position 2.
  6. At position 4, as shown in the above figure, prove the App domain without HTTPS.
  7. At position 5, provide the app domain with https:// as prefix and click the "Create" button. The App registration key with the provided app domain will be registered on the working site.
  8. Now, again, go to your Azure portal and open the App service on which we were working previously.

    Azure
    Fig: App settings of the Azure App Service
  9. Select Application settings as shown in position 1and insert the ClientId and ClientSecrect here, as shown in position 2.
  10. Provide “ClientId” string in the key portion and provide your Client Id as I have provided mine “b4f974fb-63ff-40d0-b5ba-4d323fcad9bf” in the value. And do the same for client secret. Then save it.

    Azure
    Fig: Azure App Service Overview Window
  11. Now, open the event receiver solution in your Visual Studio.

    Azure
  12. Open AppManifest.xml file under the app part of the event receiver. And select “Site Collection” and “Web” in the Scope column and select “FullControl” as their permission.
  13. From the ‘Overview’ tab of the App Service which here is My-Test-EventReceiver, download the "Publishing Profile" as shown in the photo above.

    Azure
  14. Now, from your Visual Studio, select the Project web file and click the Publish option.
  15. Now, you will get a window as follows.

    Azure
  16. So, now, select the profile. Then, click on Import portion in position 2 and then select the downloaded profile which we have already downloaded from our Azure portal.
  17. After uploading the Publish profile, click next as shown in the position 4. It will go to the “Connection” tab.

    Azure
  18. Confirm that “Publish method” is selected as Web Deploy. Then, validate the connection and click Next.
  19. And from the next window, select “Release” and click “Publish” button.
  20. Visual Studio will process the rest and deploy the event receiver in the selected App service in the Azure.
Install the App part on SharePoint Site
  1. The Client app needs to deploy in App Catalog. And then, installed in the selected site.
  2. So, to deploy the client app in the App Catalog, we need to create the client app package.

    Azure
  3. Click the event receiver’s app part and click Publish. The following window will open.

    Azure
    Fig: Package the Client App
  4. Here, click the "Edit" button which will open the window with the Client Id and Client Secret.

    Azure
  5. Here, provide the Client Id and Client Secret which we already have at step 4. Then click Finish.
  6. Now, the previous window will be visible as in “Fig: Package the Client App”. Then, click “Package the App” button as shown in position 2 (Fig: Package the Client App). Then, a new window will open as below.

    Azure
  7. Here, in the first text box, the App Service Domain URL will be already there. Confirm that the prefix is https://, not http://. The Client id will be already provided so just click Finish.
  8. The Package will be created and the output will be saved in “<Folder path>\<Solution Folder>\<Project>\bin\Debug\app.publish\1.0.0.0”.

    Azure
  9. A package file with “.app” extension will be created. Now, we have to deploy the app in our SharePoint App Catalog.
  10. After deploying the app in app catalog successfully, we can install the app on our site.

    Azure
  11. Under Site contents of the selected site, we have to click “add an app” as shown in the figure below.
  12. Then, we have to install the app we install other apps on SharePoint. After completing the installation, we can click on the app icon which will open the event receiver azure app domain page with the current site list.

    Azure
  13. This page confirms that the deployment on both, Azure and SharePoint, ends have been successful. Congratulation the deployment process is fully complete.

Creating Remote Event Receiver In SharePoint 2013

In this article, I am going to explain what the Remote Event Receiver is and how we can create in SharePoint 2013, with this example you can also learn how to create SharePoint APP with Announcement List.

Event Receiver

An event is nothing but an action, on doing some action we need to execute some code to do work, there are 2 types of Event Receivers ‘Before’ and ‘After’ events, it can also be called as ‘synchronous’ and ‘Asynchronous’ events. We can create events in various levels like Web, List/Libraries, List/Libraries Item, and Feature level.

We can add actions like Item adding, Item Added, Item updating, Item Updated etc…

Remote Event Receiver

Remote Event Receivers are same as event receivers but normal Event Receivers are hosted in SharePoint items, the Remote Event Receivers hosted in remotely for ex… we can host event receivers in SharePoint Apps.

In this example I am going to create a SharePoint App with an Announcement list, and I am going to create Remote Event Receiver on this Announcement list, added an event on Item adding, when user adding the item on the Announcement list the event is going to fire and update the item title with some text.

As this events are running remotely (Apps), so we are calling as Remote Event Receivers.

Steps to create Remote Event Receiver.

Step: 1

Create SharePoint APP Application called ‘RKSHAppWithList’ and pass the required SP web to deploy this APP.

app

Step: 2

Add new list item in the APP, select the announcement template.

list

list

Step: 3

Create WebPart Zone in the default page and add Announcements list to that. Below code will help you to add WebPart Zone and add announcement list.

Code:


  1. <h1>My App with Announcement List !!!</h1>  
  2.     <br />  
  3.     <br />  
  4.     <!-- Adding webpart zone to add the announcement list -->  
  5.     <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly"  
  6.         ID="full" Title="loc:full">  
  7.         <WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart1"  
  8.             runat="server" ListUrl="Lists/Announcements" IsIncluded="True"  
  9.             NoDefaultStyle="TRUE" Title="Announcements" PageType="PAGE_NORMALVIEW"  
  10.             Default="False" ViewContentTypeId="0x">  
  11.         </WebPartPages:XsltListViewWebPart>  
  12.     </WebPartPages:WebPartZone>  
Step: 4

Add New Remote Event Receiver to the App, this will add additional Remote Event Receiver service. The Remote Event Receivers work like a service.

service

Step: 5

Add Receiver code to change the title on item adding.

Code:

  1. public void ProcessOneWayEvent(SPRemoteEventProperties properties)  
  2. {  
  3.     Uri myurl = new Uri(properties.ItemEventProperties.WebUrl);  
  4.     using (ClientContext clientContext = new ClientContext(myurl))  
  5.     {  
  6.         if (clientContext != null)  
  7.         {  
  8.             List lstContacts =  
  9.                 clientContext.Web.Lists.GetByTitle(  
  10.                     properties.ItemEventProperties.ListTitle  
  11.                 );  
  12.             clientContext.Load(lstContacts);  
  13.             clientContext.ExecuteQuery();  
  14.   
  15.   
  16.             int cnt = lstContacts.ItemCount;  
  17.   
  18.             ListItem itemContact = lstContacts.GetItemById(cnt);  
  19.   
  20.             clientContext.Load(itemContact);  
  21.             clientContext.ExecuteQuery();  
  22.   
  23.             itemContact["Title"] = itemContact["Title"] + "  changed by RER";  
  24.             itemContact.Update();  
  25.   
  26.             clientContext.Load(itemContact);  
  27.             clientContext.ExecuteQuery();  
  28.         }  
  29.     }  
  30. }  
code

Step: 6

Build the Remote Event Service application and browse the service to confirm the service is running with no issues.

service

Step: 7

Copy the Service URL and replace that in App application Element file URL to link the APP with Remote Event Receiver with SharePoint APP.

xml

Step: 8

Change the SharePoint App property (Web Project to ‘None’), this is not only the web project we are also running the remove service in this.

service

Step: 9

Deploy the SharePoint App in the configured SP web.

Browse the APP and try to add the new Announcement item, once the item is created the Remote Event Receiver will run and change the title to updated one.

title

What is the difference between a Team Site and Communications Site?

Team Site

  • Connects you and your team to content and information to facilitate daily tasks. 
  • Exists for SharePoint Online (Team Sites) and On-Premises (Team Sites (Classic Experience)). 
  • Team Sites are for SharePoint online and can be connected to Office 365 Groups.
  • Team Sites (Classic Experience) are the most common site template for On-Premises versions and can be great for collaboration. 

Communication Site


  • Creates a site collection that can adapt to multiple viewing platforms (phones, computers, etc.)
  • Serves for group collaboration, but is not Connected to an Office 365 Group.
  • Has modern content and new Web Parts.

SharePoint on premise vs cloud


SharePoint Online

On-Premises

No servers, no hardware. Uses Microsoft Cloud data centers. Purchase and upkeep of servers and hardware is required
Internal resources are reduced. No IT strain to sustain your SharePoint environment. Updates are done automatically by Microsoft. Internal IT team must maintain servers, add updates and patches.
Information is stored in the Cloud Information is stored in-house. Good for strict legal and compliance requirements.
SharePoint Online is part of your Office 365 plan and is billed monthly per user Organization must absorb licensing costs
Information is held up to industry specific security standards which are set and verified by third parties Increased direct control over your information and compliance standards
SharePoint Online relies on Microsoft’s built-in redundancy for data centers. No control over servers. Relies on owned customizable servers and hardware. Full control of server and access services.
User interface resembles SharePoint 2016 User interface has better continuity
Tenant running on a multi-tenant server Single tenant
Microsoft manages the installation and deployment of updates and improvements Updates and improvements are installed and managed in-house
Limited custom development Freedom to do custom development
SP Admin Center and PowerShell Central Administration and PowerShell
No infrastructure requirements. Migration work might be needed. Infrastructure requirements:
  • Windows Server 2012 R2
  • .NET Framework 4.5.2 or above
  • All prerequisites installed from the Prerequisites Installer
  • SQL Server 2014
Microsoft generates backups for entire farm for SharePoint Online and ensures system redundancy so services remain available if components in data center fail Owner must create, test and manage backups of the dedicated data center
SharePoint Online has the ability to connect external users and it can easily be expanded with a variety of Azure services Infrastructure to connect external users must be built and regulated manually along with setting security features
Microsoft takes care of scaling on your behalf Scaling is your responsibility. Detecting and rectifying bottlenecks lies within the user.
Tools and functions are initially ported and constantly updated by Microsoft New tools are made available later
SLA with 99.9% availability You oversee availability

How to Create Azure WebJob For SharePoint 2013 Online

In SharePoint 2010/2013 On-Premise, we have Timer Jobs, which perform repetitive, scheduled tasks. For example, you may need a timer job to fetch Sharepoint list items and send them as reports on a daily basis. This timer job can be created as a farm solution and can be deployed in SharePoint 2010/2013 On-Premise Server, whereas in SharePoint Online, you are not allowed to deploy the farm solutions. To overcome this, you can create Azure WebJobs, which act as scheduled timer jobs for SharePoint Online.

In this article, you will learn how to create Azure WebJobs for SharePoint 2013 Online.

Prerequisites
  1. Visual Studio 2013 or latest versions.
  2. Office 365 Site. If you don’t have Office 365 site, please try trial version.
  3. Access to Azure Portal. If you don’t have an Azure account, please try the  trial version.
Create your Console Application
  1. Open Visual Studio 2013.
  2. Click File=> New => Project.
  3. Select Console Application template, enter a name and click OK button.

    Console
  4. In Solution Explorer, References and click Manage NuGet Packages.

    Solution Explorer
  5. In Manage NuGet Packages, search for “App for SharePoint Web Toolkit” and click Install.

    App for SharePoint Web Toolkit
  6. In the License Acceptance, click I Accept button.

     License Acceptance
  7. Installing the package is shown below:

    Installing
  8. Package installed successfully. Click Close button.

    Package installed successfully
  9. Make sure the below highlighted CS files are added.

    highlighted CS
  10. Open App.Config and replace the file with XML, given below, where you can specify the credentials, which allows you to execute CSOM code on your sites. Note: I am using my credentials in this article to execute the code but the best practice can be to create a service account and use it. An alternate option can be using OAuth and include authentication tokens in your requests to avoid specifying the account/password. Please refer to this article.
    1. <?xml version="1.0" encoding="utf-8" ?>  
    2. <configuration>  
    3.     <startup>  
    4.         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup>  
    5.     <appSettings>  
    6.         <add key="SPOAccount" value="vijaianand@c986.onmicrosoft.com" />  
    7.         <add key="SPOPassword" value="@Macro9876" /> </appSettings>  
    8. </configuration>  
  11. Open Program.cs and replace the file with the code, given below. Note: When you execute/run the Azure WebJob, it will create an item in “Azure Web Job List” and the modified by will be the account name which you have specified in the App.Config.
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Configuration;  
    4. using System.Linq;  
    5. using System.Text;  
    6. using System.Security;  
    7. using System.Threading.Tasks;  
    8. using Microsoft.SharePoint.Client;  
    9. namespace AzureWebJob  
    10. {  
    11.     class Program  
    12.     {  
    13.         static void Main(string[] args) {  
    14.             try {  
    15.                 using(ClientContext context = new ClientContext("https://c986.sharepoint.com")) {  
    16.                     // Use default authentication mode  
    17.                     context.AuthenticationMode = ClientAuthenticationMode.Default;  
    18.                     // Specify the credentials for the account that will execute the request  
    19.                     context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());  
    20.                     // Create List Items  
    21.                     var oList = context.Web.Lists.GetByTitle("Azure Web Job List");  
    22.                     ListItemCreationInformation newItemCreateInfo = new ListItemCreationInformation();  
    23.                     Microsoft.SharePoint.Client.ListItem newItem = oList.AddItem(newItemCreateInfo);  
    24.                     newItem["Title"] = "Item added by Azure Web Job at " + DateTime.Now;  
    25.                     newItem.Update();  
    26.                     context.ExecuteQuery();  
    27.                     Console.WriteLine("Azure Web Job: Successfully completed.");  
    28.                 }  
    29.             } catch (Exception ex) {  
    30.                 Console.WriteLine(ex.Message);  
    31.                 Console.WriteLine(ex.StackTrace);  
    32.             }  
    33.         }  
    34.         private static SecureString GetSPOSecureStringPassword() {  
    35.             try {  
    36.                 Console.WriteLine(" --> Entered GetSPOSecureStringPassword()");  
    37.                 var secureString = new SecureString();  
    38.                 foreach(char c in ConfigurationManager.AppSettings["SPOPassword"]) {  
    39.                     secureString.AppendChar(c);  
    40.                 }  
    41.                 Console.WriteLine(" --> Constructed the secure password");  
    42.                 return secureString;  
    43.             } catch {  
    44.                 throw;  
    45.             }  
    46.         }  
    47.         private static string GetSPOAccountName() {  
    48.             try {  
    49.                 Console.WriteLine(" --> Entered GetSPOAccountName()");  
    50.                 return ConfigurationManager.AppSettings["SPOAccount"];  
    51.             } catch {  
    52.                 throw;  
    53.             }  
    54.         }  
    55.     }  
    56. }  
Publish directly as Azure WebJob from Visual Studio:
  1. In the Solution Explorer, right click Publish as Azure WebJob.

    Publish
  2. Select WebJob run mode as Run on Demand. Click OK button.

    WebJob run mode
  3. Visual Studio installs WebJobs publishing NuGet Package.

    installs WebJobs publishing
  4. This adds the below mentioned file, containing the configuration for the Azure WebJob.

    configuration
  5. Select Microsoft Azure Websites as a target to publish and click Publish button.

    publish
  6. Enter the credentials for Azure portal and click New button to create a new Website in Azure portal.

    New
  7. Enter the details for creating new site and click Create button.

    Create
  8. Creating a site is in progress.

     site in progress
  9. In the Solution Explorer, Publish. Click Publish button.

    Solution Explorer

    Publish
Run/Monitor the Job and Review Logs in Azure Old Portal
  1. Navigate to Azure Portal.
  2. In the left navigation, click Web apps. Click AzureWebJobSite web app.

     WEB APPS
  3. Click WEBJOBS.

    WEBJOBS
  4. You can see the Web job which we have created. Select the job and click Run Once.

    RUN
  5. Job ran successfully, click Logs to review.

    Logs
  6. You can see WebJob details and the recent job runs.

    WebJob details
  7. Click last run job and you can see the Web job run details.

    details
  8. Navigate to SharePoint list “Azure Web Job List” and you can see a new item added successfully with the last modified by, as Vijai Anand (the account, which I used to execute the code).

    Azure Web Job List
Run/Monitor the Job and Review Logs in Azure New Portal

  1. Navigate to Azure Portal.
  2. In the left navigation, click App Services and click the Website which we have created.

    App Services
  3. In the Settings section, click WebJobs.

    Settings
  4. Select the Webjob and click Run. Once the job is completed, click Logs to see the job run details.

    webjob