Azure

Tips on how to Create Azure WebJob For SharePoint On-line

Introduction

In SharePoint 2010/2013 On-Premise, we’ve got Timer Jobs, which carry out repetitive, scheduled duties. For instance, you might want a timer job to fetch Sharepoint listing objects and ship them as experiences each day. This timer job might be created as a farm answer and might be deployed in SharePoint 2010/2013 On Premise Server, whereas in SharePoint On-line, you aren’t allowed to deploy the farm options. To beat this, you may create Azure WebJobs, which act as scheduled timer jobs for SharePoint On-line.

On this article, you’ll learn to create Azure WebJobs for SharePoint 2013 On-line.

Stipulations

  1. Visual Studio 2013 or the most recent variations.
  2. Workplace 365 Web site. For those who don’t have an Workplace 365 web site, please strive the trial model.
  3. Entry to Azure Portal. For those who don’t have an Azure account, please strive the trial model.

Create your Console Utility

  1. Open Visual Studio 2013.
  2. Click on File=> New => Undertaking.
  3. Choose the Console Utility template, enter your identify, and click on the OK button.
  4. In Resolution Explorer, right-click References and click on Handle NuGet Packages.
    NuGet Packages
  5. In Handle NuGet Packages, seek for “App for SharePoint Net Toolkit” and click on Set up.
    Toolkit
  6. Within the License Acceptance, click on the I Settle for button.
    License Acceptance
  7. Putting in the bundle is proven under.
    Package
  8. The bundle was put in efficiently. Click on the Shut button.
    Package installed successfully
  9. Ensure that the under highlighted CS recordsdata are added.
     CS files
  10. Open App.Config and change the file with XML, given under, the place you may specify the credentials, which lets you execute CSOM code in your websites. Word: I’m utilizing my credentials on this article to execute the code however one of the best observe might be to create a service account and use it. The alternate possibility might be utilizing OAuth and together with authentication tokens in your requests to keep away from specifying the account/password. Please check with this text.
    <?xml model="1.0" encoding="utf-8"?>
    <configuration>
        <startup>
            <supportedRuntime model="v4.0" sku=".NETFramework,Model=v4.5" />
        </startup>
        <appSettings>
            <add key="SPOAccount" worth="[email protected]" />
            <add key="SPOPassword" worth="@Macro9876" />
        </appSettings>
    </configuration>
    
  11. Open Program. cs and change the file with the code, given under. Word: Whenever you execute/run the Azure WebJob, it should create an merchandise in “Azure Net Job Checklist” and the modified by would be the account identify that you’ve got specified within the App.Config.
    utilizing System;
    utilizing System.Collections.Generic;
    utilizing System.Configuration;
    utilizing System.Linq;
    utilizing System.Textual content;
    utilizing System.Safety;
    utilizing System.Threading.Duties;
    utilizing Microsoft.SharePoint.Consumer;
    
    namespace AzureWebJob
    {
        class Program
        {
            static void Primary(string[] args)
            {
                strive
                {
                    utilizing (ClientContext context = new ClientContext("https://c986.sharepoint.com"))
                    {
                        // Use default authentication mode
                        context.AuthenticationMode = ClientAuthenticationMode.Default;
                        // Specify the credentials for the account that can execute the request
                        context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
                        // Create Checklist Gadgets
                        var oList = context.Net.Lists.GetByTitle("Azure Net Job Checklist");
                        ListItemCreationInformation newItemCreateInfo = new ListItemCreationInformation();
                        Microsoft.SharePoint.Consumer.ListItem newItem = oList.AddItem(newItemCreateInfo);
                        newItem["Title"] = "Merchandise added by Azure Net Job at " + DateTime.Now;
                        newItem.Replace();
                        context.ExecuteQuery();
                        Console.WriteLine("Azure Net Job: Efficiently accomplished.");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }
    
            non-public static SecureString GetSPOSecureStringPassword()
            {
                strive
                {
                    Console.WriteLine(" --> Entered GetSPOSecureStringPassword()");
                    var secureString = new SecureString();
                    foreach (char c in ConfigurationManager.AppSettings["SPOPassword"])
                    {
                        secureString.AppendChar(c);
                    }
                    Console.WriteLine(" --> Constructed the safe password");
                    return secureString;
                }
                catch
                {
                    throw;
                }
            }
    
            non-public static string GetSPOAccountName()
            {
                strive
                {
                    Console.WriteLine(" --> Entered GetSPOAccountName()");
                    return ConfigurationManager.AppSettings["SPOAccount"];
                }
                catch
                {
                    throw;
                }
            }
        }
    }
    

Publish instantly as Azure WebJob from Visual Studio.

  1. Within the Resolution Explorer, right-click Publish as Azure WebJob.
    Solution Explorer
  2. Choose WebJob run mode as Run on Demand. Click on the OK button.
    WebJob run mode
  3. Visual Studio installs WebJobs publishing the NuGet Bundle.
    Visual Studio installs
  4. This provides the below-mentioned file, containing the configuration for the Azure WebJob.
     Azure WebJob
  5. Choose Microsoft Azure Web sites as a goal to publish and click on the Publish button.
    Microsoft Azure Websites
  6. Enter the credentials for the Azure portal and click on the New button to create a brand new Web site within the Azure portal.
    New Azure portal
  7. Enter the main points for creating a brand new web site and click on the Create button.
    Create button
  8. Making a web site is in progress.
    Progress
  9. Within the Resolution Explorer, right-click Publish. Click on the Publish button.
    Publish button
    Publish web

Run/Monitor the Job and Assessment Logs in Azure Outdated Portal.

  1. Navigate to Azure Portal.
  2. Within the left navigation, click on Net Apps. Click on AzureWebJobSite net app.
    Left navigation
  3. Click on WEBJOBS.
    WEBJOBS
  4. You may see the Net job which we’ve got created. Choose the job and click on Run As soon as.
    Web jobsite
  5. The job ran efficiently, click on Logs to assessment.
    Logs to review
  6. You may see WebJob particulars and the latest job runs.
    WebJob details
  7. Click on the final run job and you’ll see the Net job run particulars.
    Web job run details
  8. Navigate to the SharePoint listing “Azure Net Job Checklist” and you’ll see a brand new merchandise added efficiently with the final modification by, as Vijai Anand (the account, that I used to execute the code).
    Azure Web Job List

Run/Monitor the Job and Assessment Logs within the Azure New Portal.

  1. Navigate to Azure Portal.
  2. Within the left navigation, click on App Providers and click on the Web site that we’ve got created.
    App Services
  3. Within the Settings part, click on WebJobs.
    Settings
  4. Choose the Webjob and click on Run. As soon as the job is accomplished, click on Logs to see the job run particulars.
    Web job run

Abstract

Thus on this article, you could have seen, learn how to create Azure WebJob for SharePoint 2013 On-line.

Know extra about our firm at Skrots. Know extra about our companies at Skrots Providers, Additionally checkout all different blogs at Weblog at Skrots

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button