December 23, 2020

How to change Internal name of Custom List OR Document Library in SharePoint Online

Issue:

Recently, we have provided a build and guideline document to our client and by mistake they have set up a library name with in-correct internal name. In starting it worked well but as the additional functionality added, it broke. As the users have started working on that. So, we have to fix the internal name anyway on client environment.

Our library internal name is “TrainingDocuments” and display name is “Training Documents”. but Client has set up “Training Documents” as internal name and this was not correct.



Solution: 

Initially, I thought it might not be possible and have to delete the document library and re-create from scratch on client environment. But then I've found 2 different ways to fix that.

Approach 1: Using SharePoint Designer 2013

Follow below steps to fix the internal name using SharePoint Designer 2013:

  • In SharePoint Designer, Open your site.
  • Navigate to All Files navigation node (not List and Libraries node),
    Note – you will need “Site Collection Administrator” permission in the site collection to see “All Files” option.

  • Find your list there
  • Right-click list
  • Rename.



Approach 2 : Using PNP PowerShell

In case you are not able to connect the site in the SharePoint designer or you do not have installed in your machine, you can do this using PNP PowerShell as well.

Note - You will need Owner permission to run this PowerShell. 

PowerShell to change Library Name:

 #Set Parameters  
 $SiteURL = "Site URL"  
 $ListName = "Library Internal Name"  
 $NewListURL = "New Library Name"  
 Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
 $List= Get-PnPList -Identity $ListName -Includes RootFolder  
 $List.Rootfolder.MoveTo($NewListURL)  
 Invoke-PnPQuery  
 #this will change library title  
 Set-PnPList -Identity $ListName -Title $NewListURL  

PowerShell to change List Name:

 $SiteURL = "Site URL"  
 $ListName = "List Internal Name"  
 $NewListURL = "New List Name"  
 #Connect to PNP Online  
 Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
 Set-PnPList -Identity $ListName -Title $NewListURL  
If you have any questions you can reach out our SharePoint Consulting team here.

December 21, 2020

How to Manage Item Level Permission with different Role Definitions using Power Automate?

Introduction:

In this blog, we will learn how to set item level permission on SharePoint List/Library using Power Automate with different role definitions. 

Scenarios:

We have come across with a requirement wherein we need to apply item level permission to a specific SharePoint group with different role definitions. In OOTB Workflow, this is very simple and easy. With Power Automate how we can manage this? We will discuss this in this article.
Below are the steps we are going to automate here!

1. Break the current Item Permission
2. Get ID for our SharePoint Group
3. Assign Role definition for a specific item to our SharePoint Group 

Step 1: Break Current Item Permission

1. Add a new "Send an HTTP Request to SharePoint" action.

2. To add/replace the permission on an item level, we first need to Break the Permission Inheritance.

Site Address: Select the site in which the List/Library resides.
Method: POST
Uri:/_api/web/lists/getByTitle('[List/LibraryName]')/items[ItemID])/breakroleinheritance(copyRoleAssignments=false, clearSubscopes=true)

Here, parameter copyRoleAssignments = true/false. This specifies if we want to copy inherited permission or not. If set to true, then it will copy the inherited permission else it will remove all the users when breaking the inheritance.

Step 2: Get ID for our SharePoint Group

1. Add a new "Send an HTTP Request to SharePoint" action.
Site Address: Select the Site in which the group resides
Method: GET
Uri: /_api/Web/SiteGroups/GetByName('[Group Name]')?$select=Id

2. Parse JSON.

Add below JSON payload in “Schema” section.
 {  
   "type": "object",  
   "properties": {  
     "d": {  
       "type": "object",  
       "properties": {  
         "__metadata": {  
           "type": "object",  
           "properties": {  
             "id": {  
               "type": "string"  
             },  
             "uri": {  
               "type": "string"  
             },  
             "type": {  
               "type": "string"  
             }  
           }  
         },  
         "Id": {  
           "type": "integer"  
         }  
       }  
     }  
   }  
 }  

Step 3: Assign Role definition for a specific item to our SharePoint Group 

1. Add "Send an HTTP Request to SharePoint" for assigning the permission to the group/user we fetched in above step.


Site Address: Select the site in which the List/Library resides.
Method: POST
Uri: /_api/web/lists/getByTitle(‘SiteName’)/items([Item ID])/roleassignments/addroleassignment(principalid=[Id from Prase JSON step], roledefid=1073741829) 
 
Here, Roledefid = id for specific role. Roledefid for following roles are as below:
Full Control = 1073741829
Edit = 1073741830
Read = 1073741826

 For specific tenant if we want to find role definition id then use below URL:

API: "[Site URL]/_api/web/roledefinitions?$select=Name,Id" 

This will give you roledefid for following access rights:

Design
Contribute
Limited Access
Limited View
Limited Edit
View Only
Set the appropriate roledefid for the provided access roles.

 

Conclusion:

This is how we can assign specific role definition to a specific group to maintain item level permission using Power Automate. 

If you have any questions you can reach out our SharePoint Consulting team here.

December 18, 2020

Binary Republik Proud to be Named a Global Leader on 2020 Clutch 1000!



Here at Binary Republik, we know it’s been a difficult year all around. Despite the conditions, we’re proud to report we’ve maintained our standards of quality and service as a leading Microsoft Technology Consulting company. We made sure that our clients had access to cutting edge technology and were able to get acclimated to a new normal.

As a wonderful way to wrap up the year, we’ve been featured in the Clutch 1000, an exclusive list of the top 1% of vendors on their platform. Clutch is a B2B market research authority that uses a one-of-a-kind ranking formula to identify key players in the services space.

We are thrilled to have been chosen as one of the top Microsoft Technology Consulting company and it proclaims our dedication and quality of the work we deliver to Microsoft ISVs, MSPs, MVPs, and more - Jaldeep Patel, Global Director, Binary Republik

We couldn’t have earned this award without the help of our wonderful clients. Take a look at some of
the kind words they had to share about our work when interviewed by the Clutch team:

“The most impressive aspect of Binary Republik was the size of both their team and their knowledgebase. Many firms only specialized in custom development or system architecture. Other firms didn't have an expert for every subject, but with Binary Republik we knew that someone on their team would be able to help us find an answer. Because of their size, they are also able to get back to us quickly while still maintaining genuine communication and professional relationship.”
                                                            – Web Applications Developer, Community College

“Binary has a great team that is focused on helping customers to solve their problems. They come to the table with an open mind and give realistic honest solutions and suggestions. They estimate and on-time delivery is unmatched”
                                                             – VP of Product & Engineering, Inkriti

“Like many companies, we've had varying degrees of success with offshore & outsourcing, especially outside Europe. However, Binary Republik displayed none of the negative aspects typically experienced with offshore vendors whilst remaining significantly more competitive than onshore vendor partners.”
                                                             – Product Manager, Education Services Company

We’re honored to be recognized by Clutch and our clients, and look forward to even more success in
2021! If you’re new to Binary Republik, contact us today to learn more about our award-winning
strategy and how it can help fuel your success in the new year!

December 9, 2020

How to Import and Export a SharePoint List or Library Template and use it in a SharePoint site.

INTRODUCTION:
In this blog, we will learn how to create a new list/library using an existing list/library as a template. SharePoint provides a feature to Import/Export a List/Library. We can use these features to make a new List/Library to the same or different SharePoint site within the domain. 

First, we will start by exporting a List/Library as a List Template.

Export a List/Library as a Template:
Here are detailed steps for exporting a List/Library as a List Template.

Step 1:
  • To create a List/Library Template, first of all, we have to navigate to List Settings where we will be able to see all permissions and management features for that list.
  • Select the “Save list as template” feature under the “Permissions and Management” section.

Note: If this feature is not visible then we need to activate the “custom script” option which can be activated by the SharePoint Administrator user only.


Step 2:

  • Inside the “Save as a template” section, we have to provide a file name, template name, and template description.
  • There is a checkbox for the "include content" option, if we want to include the content of the list then we can check this option as true, it will generate a template of the list with its content, but it will increase the template size also. The default size limit for saving a list/library template with its content is 50 MB only.

  •  After Clicking on “OK” it will show the below screen.
  • If the list/library template with the same name already exists within the site, then we will get a “template already exists” error. Then, in that case, we need to update the template name and save the template again and it will save the template successfully.


Step 3:

  • We will be able to view our newly created template in the “List template Gallery” under Site Settings of the site.
  • We can download this template by clicking on it.
  • List/library template files will be having the .stp file extension.


Import List/Library Template to a site:

Here are detailed steps for importing a List/Library template to a site.

Step 1: To import a List/Library Template navigate to the site settings and then select the “List Templates” option from there as shown below.


Step 2: 

  • We will upload the list templates here.

  • By clicking on the "Upload Document" button it will open the "Add a template" pop-up as shown below. 

  • Provide the name and title as required and save it. 

  • We can use this template to create a new list/library.


Notes:

  • For the template having look-up columns, these columns will get created successfully for the sites within the same domain, but for cross-domain sites, we have to perform the manual steps for creating these lookup columns.

  • For the template having self lookup columns, we will have to perform the manual steps for creating those columns as they do not get created properly. This condition applies for the both, same/cross domain sites.

Using a List/Library Template in a SharePoint Site:

  • You will be able to create a new list/library using your saved list templates which you have imported. These list/library templates will appear in the other app section. You can select your template as required and create a list/library.


CONCLUSION:

This is how we can create a new list/library based on the existing list/library structures. Hope this will help you. Good day!


If you have any questions you can reach out our SharePoint Consulting team here.

December 8, 2020

Resolved: [Something went wrong.] SharePoint Modern SPFx web part is not rendering in Internet Explorer 11 browser

Introduction:

Recently working with Modern SPFx web part, we were facing issue specific to only IE11 browser and the same web-part is rendered correctly in Chrome, Firefox, Edge, and Safari browsers.

Error:

We were getting error - “Something went wrong” only in IE11 browser.

We tried to debug the written code using console and have addressed multiple errors like “undefined” and “syntax errors” by adding polyfill JS and fixed those issues, but still getting the same issue in IE 11.

After detailed analysis of the code, we have found that SPFx generates class in backend JS (ES6) as you can see in the below screenshot.

What is ES6?

ES6 refers to version 6 of the ECMA (European Computer Manufacturers Association) Script programming language. ECMA Script is the standardized name for JavaScript, and version 6 is the next version after version 5, which was released in 2011. It is a major enhancement to the JavaScript language, and adds many more features intended to make large-scale software development easier.

ECMAScript, or ES6, was published in June 2015. It was subsequently renamed to ECMAScript 2015. Web browser support for the full language is not yet completed, though major portions are supported. So, All major web browsers support some features of ES6. However, it is possible to use software known as a transpire to convert ES6 code into ES5, which has better supported on mostly all browsers.

Root cause:

This Modern SPFx web part generates ES6 features keyword like class, arrows, Destructuring, Unicode, promises, let, const, etc. Those ES6 features do not support in IE11 browser.

Solution:

In our SPFx web-part solution, we have “tsconfig.json” file and In that file, we have “target” property in “compilerOptions” object. We have set value “es6” in the “target” property. Thus, SPFx generates class, arrows, unicode, const, etc. keywords according to ES6 feature and those are not supported in IE 11 browser.

To resolve this issue, we need to downgrade “target” property from “es6” to “es5” value in “complierOptions” object.



After doing this change in “tsconfig.json” file, rebuild the web-part and deploy latest package on App catalog. SPFx webpart will be working in IE 11 browser.

Below table shows which browser supports which ECMAScript feature.

Browser

ES5 (Browser Version)

ES6 (Browser Version)

ES7 (Browser Version)

Chrome

Yes (23)

Yes (23)

Yes (68)

Firefox 

Yes (21)

Yes (54)

No

IE           

Yes (9*)

No

No

Edge

Yes (10)

Yes (14)

No

Safari

Yes (6)

Yes (10)

No

Opera

Yes (15)

Yes (38)

Yes (55)


If you have any questions you can reach out our SharePoint Consulting team here.

December 3, 2020

Power Automate | Steps to manually trigger a flow from a SharePoint Library OR List

Introduction:

In this blog, we will learn how we can manually trigger a Power Automate workflow on any SharePoint List Item or Document. The flow will be triggered whenever the user needs any action to be carried out.

Following are the detailed steps to create a flow. 

Step 1:  Create a new flow by clicking Create and select Instant flow. The instant flows are the one those are manually triggered.

 

Step 2:  Provide a name to the Flow and specify the trigger action you want to carry out. For the given example, we have chosen for a selected file trigger for a SharePoint file.


Step 3:  For the Action, mention the Site Address and Library Name where you want the Flow to be executed.

                             

Step 4:  Select an action you want to perform for the Flow and then Save it. For this example, we have added a Send an email action along with it. So it would send a mail every time the flow runs.

                                                     

Now, to execute the flow through SharePoint Library, Follow the below steps for a selected file.

Go to the SharePoint Library you've mentioned while creating the Flow.

Step 1:  Click the Ellipse button on any file in Library.

                  

Step 2:  Select Automate and select the flow that we've created.

                                        

Step 3: Select Run Flow.

 


If you have any questions you can reach out our SharePoint Consulting team here.

December 2, 2020

How to clear Office UI Fabric multi-select dropdown in SPFx webpart with React Framework?

Scenario:

We implemented a webpart using SharePoint Framework (SPFx) that includes the filter functionality. As per the requirement, we have one dropdown that allows multiple options selection for filter functionality. Now when user clicks on the "Clear Filter" button, it should clear the selection of options from the dropdown.

Below is our dropdown control with multiple items selection:
 <Dropdown  
  multiSelect  
  className="multiSelectDrodpown"  
  options={currentObj.state.dropdownOptions}  
  defaultSelectedKeys={this.state.selectedOptions}  
  onChanged={(val) => currentObj.filterData(val)}           
 ></Dropdown>  

Note:
  • dropdownOptions state contains all the options which will be display in multi select dropdown control.
  • selectedOptions is the state which contains the options which are currently selected.


Problem Statement:

  • When we select the values from the multi-select dropdown control, we pass those values to defaultSelectedKeys parameter of the multi-dropdown control to show the selected values. 
  • But when we clear the value of the state which we are using in defaultSelectedKeys parameter(selectedOptions state in our scenario), it does not clear the selection of multi-select dropdown.


Solution:

  • To resolve this issue, we need to use the "key" parameter of the office fabric UI dropdown control and set the unique number as the value on click event of the "Clear Filter" button.
  • Using a new value for key parameter means, it renders fresh control each time.
  • Here, we use randomIndex state to set a new key value to generate a random number. Below is an example to use key attribute:
 <Dropdown  
  multiSelect  
  className="multiSelectDrodpown"  
  options={currentObj.state.dropdownOptions}  
  defaultSelectedKeys={this.state.selectedOptions}  
  onChanged={(val) => currentObj.filterData(val)}     
  key={this.state.randomIndex}        
 ></Dropdown>  
  • Now, when user clicks the "Clear Filter" button, it will update randomIndex state and set a new random number as its value.
  • Here, we are using Math.floor and Math.random()  function to generate random numbers.
 private async clearFields() {  
      await this.setState({    
          randomIndex: Math.floor(Math.random() * 6) + 1          
       });  
 }  


Conclusion:

This is how we can clear the value of multi-select dropdownlist in SharePoint Framework (SPFx).

If you have any questions you can reach out our SharePoint Consulting team here.

November 26, 2020

2020 COVID 19 Pandemic Edition - Why should you send your work Offshore/Outsource?

Companies expected to outsource more work due to the COVID-19 pandemic



Outsourcing and/or offshoring is one of the important and key strategic approaches in complex, dynamic, and competitive global supply chains. 

What is Outsourcing?

Outsourcing is a business agreement, either domestic and/or international (known as offshoring), and strategic management initiative for gaining competitive advantage of a firm by contracting out their existing internal and/or external non-value added functions, and/or value-added functions, and/or core competencies to the competent supplier(s) to produce products and/or services efficiently and effectively for the outsourcing firm.

A critical review of some empirical research articles published between 2010 and 2019 suggests that ‘outsourcing can produce positive, negative, mixed, moderated or no significant impact on the firm’. Cost-saving, improved management effectiveness and flexibility, access to market, and better product/service quality are some of the benefits of outsourcing and offshoring.

Sending work overseas has become very popular, and many companies are well aware of the benefits. All kinds of services, such as customer service, transcription, accounting, web hosting, software development, and web design, are sent offshore every year. Offshoring often offers a fast turnaround and the ability to ramp certain functions up or down and it can allow in-house staff to focus on more critical tasks. 

As businesses work towards operating in a changing environment following the Covid-19 pandemic, many of them are expected to outsource more work, according to a report by technology firm NTT.

The ‘2020 Global Managed Services Report’, based on a survey of 1,250 executives in 29 countries including India, said that 45% of organizations will outsource more than insourcing in the next 18 months, with 57% citing security risks as a key challenge of managing IT in-house.

Demand for expertise in cloud infrastructure outsourced to service providers is set to increase in 18 months to 77% while new product development will be the most common impact on IT decision making in the next 12 months, said Skendrovic.

Other findings of the survey include:

- Reducing security risks is not only the biggest challenge faced by IT teams globally, it’s the top reason for service provider consideration
- 48% of business leaders already acknowledge a need to optimize the workplace environment
- Technical expertise is the number one driver for the selection of a service provider, with cloud infrastructure and security leading the demands



Pros

There are reasons many companies are sending more work offshore than ever before. 

• It’s often cheaper: Sending work overseas can be substantially cheaper. Educated and experienced people in Asia, parts of Latin America, and Europe can be hired on contract for much less than people in the U.S.

• You can pay back investors faster: Businesses often must do what’s best for their investors and stakeholders. Paying less gives you more flexibility to return the profit to investors.

• Help improve developing economies: Outsourcing work can create many jobs in other countries. Developing countries in Asia and Latin America are common places that businesses from the U.S. outsource work to.

• Faster turnaround times: While you are asleep, your offshore company can work on getting your project done. Time zone differences can help when you need your work done as fast as possible.

Cons

Data security: You don’t want company or client data getting into the wrong hands, but overseas vendors may not adhere to the same data security standards as your company. Anytime companies in the medical field outsource work, for instance, they must choose vendors that comply with the Health Insurance Portability and Accountability Act.

• Communication: When speaking with nonnative English speakers, faulty communication may occur at some point. Maybe they interpret something in another way, or you agree to something assuming an entirely different intention. 



If sending work offshore seems like the right move for you, there are a few questions to consider to make the best decision: Do you need fast turnaround times that you can only get by offshoring? Are you sending confidential files? Will having more room in your budget help your business pay investors sooner? Are you willing to put in the time to overcome any communication barriers? Do you have time to check every document for errors? 

Being the #1 Go to Offshore Partner for every Microsoft Technology such as SharePoint, MS Teams, Power Apps, Power Automate, Power BI, Azure, and Dynamics 365, Binary Republik is just 1 step away from handling all your needs.


November 20, 2020

Show values based on Lookup List Conditions for Lookup Column in Power Apps

Overview:

In this article, we will learn how we can show only specific values as Lookup value based on some conditions in Power Apps.

Real-Life Business Use Case:

We have come across a scenario where we have two SharePoint lists.

Domains List:


Request List:


 - Domain is a Lookup column from Domains List in the Request List.

 - We are implementing a Power Apps Form for Requests List.

 - We only want to show those Domains which are active, so how can we achieve this?

Let’s get started!


Step 1: Open Power Apps Form. By default, all values appear in the Lookup Dropdown.

Below is the code for the Default event which is available for the lookup dropdown.


Step 2: Now, we need to change the code with the following code.

 Filter(  
   RenameColumns(  
     AddColumns(  
       RenameColumns(  
         Choices([@Requests].Domain),  
         "Id",  
         "MID"  
       ),  
       "Status",  
       LookUp(  
         Choices([@Requests].'Domain:Status'),  
         Id = MID  
       ).Value  
     ),  
     "MID",  
     "Id"  
   ),  
   Status = "Active"  
 )  


Understanding the code:

 - By default, Lookup has two columns, ID and Value. With the above formula, we added one additional column –“Status” by using AddColumns() function.

 - To achieve this, we need to use the "RenameColumns" function to make the exact final structure that the lookup value expects.

 

- Now, let’s test the result. We can see only Active records in the dropdown.

 

- Now, let’s fill the form and save the value. 


 - The values are stored successfully in the SharePoint list.


Conclusion:

This is how we can apply a lookup list condition to show only active requests in the Lookup column. Hope this is clear now! Stay connected for amazing Power Apps Articles! Happy Power Apping!

If you have any questions you can reach out to our SharePoint Consulting team here.

November 12, 2020

How to perform Azure App Only Authentication with SharePoint in .Net Core (Azure Function)

Introduction:

In the .NET Framework, there were native classes like  "SharePointCredentials" and "AuthenticatinoManager" which were used for SharePoint Authentication, but now they are removed.

The major difference compared to the .NET Framework CSOM is that the authentication is completely independent of the CSOM library now.

Resolution:

.NET standard CSOM now uses the OAuth for authentication. So we need to get an access token and pass it along with the call to SharePoint Online.

So in this blog, we will learn how to perform Azure App-Only Authentication with SharePoint in new .NET Standard CSOM to get data from SharePoint Online.

When we are using App-Only Authentication, we will have two options:
1. Azure Active Directory App Registration with the client certificate.
2. Create SharePoint App using AppRegNew.aspx and AppInv.aspx.

Here we will discuss the Azure AD App Registration approach.

Step 1:

  • First, we need to register a new app in the Azure Active Directory.
  • Go to http://portal.azure.com/ and select "Azure Active Directory". Now from the "App registrations" option in the left panel, register a new app.


Step 2:

Now we will grant the required permission to the app we created in Step 1. Open the newly created app and click on "API permissions" and click on "Add a permission".

Now select "SharePoint permission" as per your requirement and grant the admin consent. Here we needed "Full Control" permission for SharePoint so we have added "Sites.FullControl.All" and "Sites.Manage.All" permissions.


Step 3:

    1. CertificateName.cert
    2. CertificateName.pfx
  • Consideration: Keep note of the password which you have used to generate a certificate.

Step 4:

  • Now we will configure this certificate with our Azure AD App. 
  • Go to your Azure AD App. Now click on "Certificates and client" from the left panel and click on the "Upload certificate" button.
  • On clicking the "Upload certificate", it will open a panel at the top and allows you to upload the file. Here you need to upload the ".cert" file.

Step 5:

  • Make sure you have selected all required permissions in API Permissions and admin consent has been granted for all required permissions.

Step 6:

  • Now we will create an Azure Function solution using Visual Studio 2019.


Step 7:


Step 8:

  • Now in the Azure Function solution, we need to read the ".pfx" file which is uploaded in our solution. To read the file from the Azure Function solution we need execution context.
  • We can get the execution context using the below parameter in the Azure Function:
          
 ExecutionContext executionContext  

  • Below is the code snippet for how to use execution context:
 [FunctionName("Function1")]  
 public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext)  

  • Now using this execution context, we can get the ".pfx" file as below:
 var Sfilepath = $"{ System.IO.Directory.GetParent(executionContext.FunctionDirectory).FullName}\\Certificate\\CertificateFilename.pfx";  

  • Here we have uploaded the file in the Certificate folder. So the Sfilepath variable we are reading a file from the Certificate folder.

Step 9:

  • Now we will get ClientContext using this Certificate File and Application ID.
  • To get the context, first, we need an access token.
  • To get the access token we need Application ID, Certificate File Path, Certificate File Password, Tenant ID, and Permission Scope.
  • Permission scope will be as below:
  public static string[] permissionscopes = { "https://tenantname.sharepoint.com/.default" };  

  • We will use the below method to get the access token:
 internal static async Task<string> GetApplicationAuthenticatedClient(string clientId, string Sfilepath, string certificatePassword, string[] scopes, string tenantId)  
     {  
       X509Certificate2 certificate = new X509Certificate2(certThumprint, certificatePassword", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);  
       IConfidentialClientApplication clientApp;  
       clientApp = ConfidentialClientApplicationBuilder  
       .Create(clientId)  
       .WithCertificate(certificate)  
       .WithTenantId(tenantId)  
       .Build();  
       AuthenticationResult authResult = await clientApp.AcquireTokenForClient(scopes).ExecuteAsync();  
       string accessToken = authResult.AccessToken;  
       return accessToken;  
     }  

  • We can call the above method as below:
 var accessToken = await GetApplicationAuthenticatedClient(clientId, Sfilepath, certificatePassword, permissionscopes, tenantId);  

  • Now the "accessToken" variable will contain the access token.

Step 10:

  • Now using the access token which we get in Step 8, we will generate client context.
  • We can use the below method, which will return the client context. We will need the Site URL for which we want the client context and the access token.
 public static ClientContext GetClientContextWithAccessToken(string targetUrl, string accessToken)  
     {  
       ClientContext clientContext = new ClientContext(targetUrl);  
       clientContext.ExecutingWebRequest +=  
       delegate (object oSender, WebRequestEventArgs webRequestEventArgs)  
       {  
         webRequestEventArgs.WebRequestExecutor.RequestHeaders["Authorization"] =  
   "Bearer " + accessToken;  
       };  
       return clientContext;  
     }  

  • We can call the above method as below:
 var clientCtx = GetClientContextWithAccessToken(siteUrl, accessToken);  

Step 11:

  • Now we have the client context of the Site URL which you have used in step 9.
  • So we can now use the client context for any operations we want to perform programmatically with CSOM.
 Web web = clientCtx.Web;  
 clientCtx.Load(web);  
 clientCtx.ExecuteQuery();  

Conclusion:

This is how we can authenticate to SharePoint from .Net Core with the use of Azure App-Only Authentication. 

If you have any questions you can reach out our SharePoint Consulting team here.