Tuesday, 25 May 2021

Add & Remove App Catalog SharePoint Online Site Collection



#Login with Global Admin id and update the email address below

Connect-SPOService -Url https://xxx-admin.sharepoint.com -credential {user}@xxx.com

# get a reference to the site collection where the site collection app catalog should be created

$site = Get-SPOSite https://xxx.sharepoint.com/sites/yyy/ 

# remove site collection app catalog

Remove-SPOSiteCollectionAppCatalog -Site $site

# Add site collection app catalog

Add-SPOSiteCollectionAppCatalog -Site $site


Note : Account used to create App Catalog Site Collection, must be Site Collection Administrators on both the tenant-level App Catalog and the target Site Collection


SharePoint Online - Copy site pages between site collections, using PnP-PoweShell

Copy Site Page from one site collection to other site collection using PnP-PowerShell

try{
    $srcSiteURL   = "https://xxxxx.sharepoint.com/sites/xxxxx/"
    $destSiteURL  = "https://xxxxx.sharepoint.com/sites/yyyyy/"
    $pageName = "test.aspx"
    
    Connect-PnPOnline -Url $srcSiteURL -Credentials SharepointCredential
    $tempFile = [System.IO.Path]::GetTempFileName();
    Export-PnPClientSidePage -Force -Identity $pageName -Out $tempFile
    
    Connect-PnPOnline -Url $destSiteURL -Credentials SharepointCredential
    Apply-PnPProvisioningTemplate -Path $tempFile
    Write-Host "Success"
    }
catch{
    Write-Host -ForegroundColor Red 'Error ',':'$Error[0].ToString();
    } 

Reference Link:
https://pnp.github.io/powershell/cmdlets/Export-PnPPage.html 

How to filter a SharePoint list or library using URL parameters


?FilterField1=[IntFieldName]&FilterValue1=[FilterValue]

Filtering yes/no or true/false values

If your filter isn’t working for yes/no columns, replace “no” with 0 and “yes” with 1 in your URL.

SharePoint List Item Query String Filter on Multiple Values

If you want to filter on multiple values then you can pass values separated by a semicolon(;). See like below:

?FilterName=Country&FilterMultiValue=IN;SL


Remember here the filter column name is the internal name of the column, not the display name.

You can add up to 10 FilterField and FilterValue like below:

/Lists/MyTestingList/AllItems.aspx?FilterField1=Country&FilterValue1=IN&FilterField2=Title&FilterValue2=Item-2……


SharePoint List Item Query String Filter on wildcard characters

You can also filter SharePoint list items filter items based on wildcard characters like below:

/Lists/MyTestingList/AllItems.aspx?FilterName=Country&FilterMultiValue=*IN*


Monday, 16 November 2020

Azure Functions for .NET- VS Code

 Install dependencies 

Before you can get started, you should install Visual Studio Code. You should also install Node.JS which includes npm, which is how you will obtain the Azure Functions Core Tools. If you prefer not to install Node, see the other installation options in our Core Tools reference. 

Run the following command to install the Core Tools package: 

npm install -g azure-functions-core-tools 
 

The Core Tools make use of .NET Core 2.1, so you should install that, too. 

Next, install the Azure Functions extension for Visual Studio Code. Once the extension is installed, click on the Azure logo in the Activity Bar. Under Azure: Functions, click Sign in to Azure... and follow the on-screen instructions. 

 
 

Create an Azure Functions project 

Click the Create New Project… icon in the Azure: Functions panel. 

You will be prompted to choose a directory for your app. Choose an empty directory. 

You will then be prompted to select a language for your project. Choose dotnet. 

 
 

Create a function 

Click the Create Function… icon in the Azure: Functions panel. 

You will be prompted to choose a template for your function. We recommend HTTP trigger for getting started. 

 
 

Run your function project locally 

Press F5 to run your function app. 

The runtime will output a URL for any HTTP functions, which can be copied and run in your browser's address bar. 

To stop debugging, press Shift + F5. 

 
 

Deploy your code to Azure 

Click the Deploy to Function App… (blue up arrow) icon in the Azure: Functions panel. 

When prompted to select a function app, choose {  }App 

Azure AD app via Graph API

 Using an Azure AD app via Graph API - Access SharePoint Data using Postman 

Step-1 : Register an app in Azure AD  

  • Go to ADD in azure portal  

  • Navigate to App registrations --> New Registration --> Provided the proper name --> Create. 

  • Open the created new App  --> go to Certificates & secrets section --> create a new client Secret and save the Value  

 

 

  • Open the create new app again --> go to API permissions --> set the permission  

 

 

  • Finally copy the Directory (tenant) ID & Application (client) ID for overview 

 

Step-2: Postman to generate the token using POST request 

  • Create an environment variables. 
     

Variable        Initial Value 

azureApp_clientId   

  application id copied earlier 

azureApp_clientSecret   

  key copied earlier 

directoryId        

 Id of the Azure Active Directory 

 

  • Access Token Request 

Now that the environment is set up, it’s time to send a POST request to get the token. Create a new request in Postman, name it as “Get Access Token For Graph” and change it’s request type to “POST”. 

The URL will be 

{{directoryId}} is an environment variable. So when we send the request {{directoryId}} will be replaced with the value we specified earlier. 

Click on the “Body” tab of the request and add the following Key Value pairs 

  

KEY        VALUE 

grant_type  

   client_credentials 

client_id     

{{azureApp_clientId}} 

client_secret  

   {{azureApp_clientSecret}} 

scope        

 https://graph.microsoft.com/.default 

 

Now click on “Tests” tab in the request and add the following javascript. 

  

var json = JSON.parse(responseBody); 

postman.setEnvironmentVariable("azureApp_bearerToken", json.access_token); 

  

This code runs after the request is made. It extracts the “access token” from the response, creates an environment variable called “azureApp_bearerToken” and assigns it’s value to the retrieved access token. 

This should have created a variable called “azureApp_bearerToken” in the environment and assigned the value of it to the retrieved token 

 

Step-4 : Postman Get query with Site ID, List ID and access token 

 

Now that we have the site id and list id, let’s create a couple more postman environment variables to store those. 

Variable        Initial Value 

siteId_ModernTeam    

 the site id obtained from graph 

listId_Test       

  List    the list id obtained from graph 

  

We are now ready to make the request to get the list items. To do that create a new GET request in Postman with the name “Get List Items Using Graph”. The URL will be 

  

This should return all the items in the list with their title. 

To specify the access token for the request, click on the “Headers” tab and add the following 

  

KEY        VALUE 

Authorization  

   Bearer {{azureApp_bearerToken}}