Wednesday, September 23, 2020

Azure Function Chaining - Get web Title in SharePoint Online

Visual Studio sample code

Here is the orchestration as a single C# file in a Visual Studio project:
using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Azure.WebJobs; namespace VSSample { public static class HelloSequence { [FunctionName("E1_HelloSequence")] public static async Task<List<string>> Run( [OrchestrationTrigger] DurableOrchestrationContextBase context) { var outputs = new List<string>();
var SiteUrl="https://tenant.sharepoint.com/sites/TestSite";
outputs.Add(await context.CallActivityAsync<string>("E1_GetSiteTitle", SiteUrl)); return outputs; } [FunctionName("E1_GetSiteTitle")] public static string GetSiteTitle([ActivityTrigger] DurableActivityContextBase context)
        {
            string siteDescription = "this is communication site for test purpose";
            string siteUrl = "https://gidcmylan.sharepoint.com/sites/" + webTitle;
            string tenantURL = "https://gidcmylan-admin.sharepoint.com";
            string UName = "test@gidcmylan.onmicrosoft.com";
            string Password = "Mylan@123";
            string communityUrl = string.Empty;

            SecureString securePwd = new SecureString();
            foreach (char c in Password)
            {
                securePwd.AppendChar(c);
            }
            securePwd.MakeReadOnly();
            /* Create Site using CreateSiteAsync method */
            using (var ctx = new ClientContext(siteUrl))
            {
                // ctx.Credentials = new NetworkCredentials(userName, pwd);
                ctx.Credentials = new SharePointOnlineCredentials(UName, securePwd);
                ctx.RequestTimeout = Timeout.Infinite;

                // Just to output the site details
                Web web = ctx.Web;
                ctx.Load(web, w => w.Title);
                ctx.ExecuteQuery();
                communityUrl = "Web Title is :" + web.Title;
            }

            return $"Hello {communityUrl}!";
        }
} }

No comments:

Introduction of Preferred Integrated Development Environments (IDEs)

Getting Started with IDE Dear Developer, a preferred set of industry-leading, fully-managed Integrated Development Environments (IDEs)—savin...