CDN

Enable CDN

Enabling the Content Delivery Network (CDN) in SharePoint Framework (SPFx) can significantly improve the performance of your SharePoint Online pages by caching static assets closer to the users. Here’s a step-by-step guide to enable the Microsoft 365 CDN for your SPFx solutions:

  1. Connect to SharePoint Online:
    • Open the SharePoint Online Management Shell and connect to your SharePoint Online tenant using the following command: Connect-SPOService -Url https://your-tenant-admin.sharepoint.com
  2. Enable the Public CDN:
    • Run the following command to enable the public CDN: Set-SPOTenantCdnEnabled -CdnType Public
  3. Add Origins to the CDN:
    • Specify the origins (libraries) that should be included in the CDN. For example:Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl */sites/CDNLibrary
  4. Verify CDN Settings:
    • Check the status of your CDN settings with these commands:
      • Get-SPOTenantCdnEnabled -CdnType Public
      • Get-SPOTenantCdnOrigins -CdnType Public
      • Get-SPOTenantCdnPolicies -CdnType Public

Disable CDN

To disable the Content Delivery Network (CDN) for your SharePoint Framework (SPFx) solutions, you can use the following steps:

  1. Connect to SharePoint Online:
    • Open the SharePoint Online Management Shell and connect to your SharePoint Online tenant: Connect-SPOService -Url https://your-tenant-admin.sharepoint.com
  2. Disable the Public CDN:
    • Run the following command to disable the public CDN: Set-SPOTenantCdnEnabled -CdnType Public -Enable $false
  3. Remove CDN Origins:
    • If you have specific origins set up for the CDN, you can remove them using: Remove-SPOTenantCdnOrigin -CdnType Public -OriginUrl */sites/CDNLibrary
  4. Verify CDN Settings:
    • Check the status of your CDN settings to ensure they are disabled:
      • Get-SPOTenantCdnEnabled -CdnType Public
      • Get-SPOTenantCdnOrigins -CdnType Public

Configuring SPO Tenant

In this post you are going to create a new tenant for use throughout all the examples that are mentioned in SPO-Admin – development categories. We are going to install the
necessary PowerShell tools for connecting to SharePoint Online and Azure Active Directory. Finally, you will create some users that will be used for testing during the course and install the Office client.

Prepare SharePoint management PowerShell:

  • Run Windows management Shell as admin
  • Type install-module MSOnline and press enter
  • Run the following commands in order:
          a. $Credential = get-credential – Enter your. steve@CkXXXX.onmicrosoft.com user name and password,
    click OK
         b. Import-Module MSOnline
          c. Connect-MsolService –Credential $Credentia
  • Get-MsolUse –> you should receive the user data such as principal name, display name & if the user is licensed or no

Connect to your tenant

Open notepad or any text editor and add the following commands:

  • Import-Module Microsoft.Online.SharePoint.PowerShell
  • Connect-SPOService -Url https://tenant-admin.domain/ -credential UserName
  • save the file with extension ps1
  • run the file from SharePoint online management shell.

Then you will receive a popup to enter the password

You can open SharePoint online Management shell and execute directly the connect command

Thousand separator in Numeric / Calculated field

SharePoint Online – By Heba Hegab

SharePoint list is the most widely used to store data. They have different types of data in order to help storing the data in correct format. Numeric data types has special format to display big numbers by using thousand separator, So, if you have a numeric column or calculated field with output numeric will suffer from this issue.

comma separator in calculated field

If you create column from list as numeric data type, you will have the option to remove the separator. But if you are adding from the site settings you won’t have this option.

Also, calculated field doesn’t have this option. So, you will need another way to solve this issue.

Now to create calculated field and remove the comma separator, we are going to use JSON to remove it. In the column settings, go to column validation and paste the following code

{“$schema”:”https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,”elmType”:”div”,”attributes”:{“class”:”=if(@currentField > 0,”, ”)”},
“children”:[{
“elmType”:”span”,”style”:{“display”:”inline-block”}},{“elmType”:”span”,”txtContent”:”@currentField”}
]}

Create Task in Task list – C#

SharePoint onPrem 2013, 2016, 2019

Create SharePoint list item has the same logic but for task list you will need assigned to.

Assigned to is site column if type people or hyperlink. So, it’s expecting to send by code a valid SharePoint user and this can be done by using EnsureUser and SPFieldUserValue .

EnsureUser –> will retrieve a valid SPUser

SPFieldUserValue –> will take the SPUser and retrieve and save the data in correct format.

using (SPSite site = new SPSite("https://serverName/sites/TEST"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList("Tasks");
                    if (list != null)
                    {
                        // get the SharePoint group
                        SPUser user = web.EnsureUser(@"domainName\userName");
 
                        // Create a new task item
                        SPListItem task = list.Items.Add();
                        SPFieldUserValue assignTo = new SPFieldUserValue(web, user.ID, user.Name);
                        task["AssignedTo"] = assignTo; 
                        task["Title"] = "Testing";
                        task["Description"] = "Testing";                       
                        task.Update();
                    }
                }
            }
        }

SharePoint feature

SharePoint onPrem 2013, 2016, 2019

Uninstall feature from SharePoint is one of the most important issue especially if you don’t know GUID for it. To uninstall the feature, you will need to get the feature first. Open SharePoint CMD as admin and use the following command

Get-SPFeature | where { $_.DisplayName.StartsWith("the feature name to be removed") }

Also, the feature can be found by GUID as in the following command

Get-SPFeature | where { $_.Id.ToString().StartsWith("Feature GUID") }

The complete command to uninstall the feature

Get-SPFeature | where { $_.DisplayName.StartsWith("feature name") } |
 foreach { Uninstall-SPFeature $_.Id -confirm:0 -force }

This command is very helpful especially when the retract didn’t go well and the feature became orphaned feature .

SPS outgoing e-mail

SharePoint 2013, 2016, 2019 OnPrem

In some scenarios, developers will need to test the SharePoint configuration for outgoing emails. Usually, this check will take place before implementing C# code to send emails from SharePoint web parts. The following script can be written inside ps file and run from powershell cmd.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration Parameters
$SiteURL="http://sps:portNo/"
$Email = "receiver email"
$Subject = "Test Email from SharePoint"
$Body = "Test Email Body"
 
#Get the Web
$Web = Get-SPWeb $SiteURL
 
#Send Email using SPUtility SendEmail method
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($Web ,0,0,$Email,$Subject,$Body)