Articles about European Sharepoint Hosting Service
Posts tagged SharePoint 2013 Hosting Italy
SharePoint 2013 Hosting – HostForLIFE.eu : How to Implement Custom Image Handler n SPFx Rich Text Editor Using Angular 4?
Jul 24th
In my previous article, I described how to integrate Rich Text Editor in SharePoint Framework (SPFx) Angular webparts. Now, let’s see how do we implement custom image handler in the same. So, you are able to save the images uploaded in Rich Text Editor to the desired destination folder. Let’s directly go to the implementation with the below steps.
Get the ngx-quill editor instance.
Once the editor is created/rendered in our View, we will need to get the ngx-quill editor instance. It will be helpful to add our custom handlers to the controls in the editor or even you could add your own custom controls.
Use the onEditorCreated event to get the editor instance. Please find the below code snippet.
Component HTML file.
Component.ts file
This event will be raised once the editor is created in the page, so we will have access to the toolbar of the Quill Editor. In the second line of the method, we get the toolbar module in the variable toolbar. Image control name in the quill toolbar is image. In the toolbar instance, we do have a method to add handlers.
The last line of code in the above method demonstrates how to register the custom image handler in quill-editor toolbar.
How to get current page context in the quill editor handler method?
If you notice in the above method, highlighted content bind(this) will get you the current page context inside the handler whenever an image icon is clicked in the quill editor toolbar.
How to insert the selected image in quill editor using image handler?
Once we are into the handler method the first thing we need to do is to get the selection range, i.e, to get the cursor range so we could insert the image where the cursor points to. To get the range of index use the below line of code in the handler,
1 |
const range = this.editorInstance.getSelection(); |
Now, let’s pop up the image selection window using the default image control in the HTML. Create image control dynamically inside the handler and use its change event to process the selected image.
Please find the below handler method with all the functionalities,
The change event listener should be registered before clicking the dynamically created file control.
We will be using FileReader to read the file and convert it into a base64 string and in the above code snippet, we got base64String in the variable base64result.
Once we got the base64string you can insert the image in the editor by using the insertEmbed method of quill editor instance like below,
1 |
this.editorInstance.insertEmbed(range.index, 'image', base64result); |
In the above line, if you notice, there is range.index which is used to insert the image at the appropriate location in the editor.
How to save the image in a library in SPFx?
SharePoint provides a lot of REST API endpoints which could be helpful to manipulate data in SharePoint. Now, let’s see how to upload image to SharePoint from SPFx using REST API.
Method – POST
URL
{ReplaceYourSiteUrl}//_api/web/GetFolderByServerRelativeUrl(‘{ServerRelativeUrlOfFolder}’)/Files/add(url='{FileName}’,overwrite=true)
The beauty of this code is that you have no need to pass the base64 to this API. You can directly pass the FileObject selected from the file control. Since we are mentioning content-type as multipart/form-data in API Request, SharePoint will handle it for you.
This article described just a sample about integrating the custom image handler in ngx-quill editor and how to insert it in the cursor point position and upload it at the desired location in SharePoint.
If you have any questions/issues about this article, please let me know in the comments.

SharePoint 2013 Hosting – HostForLIFE.eu : Migrate Files From Folder Share To SharePoint Online Using PowerShell
Jul 19th
This tool allows you to migrate lists or files from your SharePoint on-premises document libraries or from your on-premises file shares and easily move them to either SharePoint or OneDrive in Office 365. It is available to Office 365 users.
In the latest version, Microsoft has introduced PowerShell cmdlets to perform migration that has all features of the SharePoint Migration Tool (SPMT).
Click here to download the SPMT latest version 2.1.100.0 (currently in open beta). The PowerShell .dll’s will be copied to %userprofile%\Documents\WindowsPowerShell\Modules location.
Copy the below script and paste it in a Notepad. Save the file as SPMTMigration.ps1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# Module Location $Global:ModulePath = "C:\Users\Sharepoint\Documents\WindowsPowerShell\Modules\Microsoft.SharePoint.MigrationTool.PowerShell" # File Share Source Location $Global:FileShareSource = "C:\Users\Sharepoint\Desktop\DeploymentAutomation" # SharePoint Online Target Site Details $Global:SPOUrl = "https://c986.sharepoint.com/sites/dev" $Global:SPOCredential = Get-Credential $Global:ListName="Documents" # Import SPMT Module Import-Module ($modulePath + "\Microsoft.SharePoint.MigrationTool.PowerShell.psd1") # Create a migration session and initialize it Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force # Add a new migration task to the registered migration session Add-SPMTTask -FileShareSource $Global:FileshareSource -TargetSiteUrl $Global:SPOUrl -TargetList $Global:ListName # Start the registered SPMT migration Start-SPMTMigration # Cancel the current migration session Stop-SPMTMigration # Remove the SPMT migration session created Unregister-SPMTMigration |
Open PowerShell window and run the following command.
1 |
>cd "<folderlocation>" |
folderlocation – where the SPMTMigration.ps1 file is saved
Run the following command
1 |
>.\SPMTMigration.ps1 |
Enter the SharePoint Online site credentials in the pop-up and enter OK. After a few minutes, the files from folder share will be migrated to SharePoint Online site.
Thus, in this blog, you saw how to migrate files from Folder Share to SharePoint Online using PowerShell based on the SharePoint Migration Tool (SPMT) migration engine.
SharePoint 2013 Hosting – HostForLIFE.eu : Is Server Side Code Dying Out In SharePoint?
Jul 10th

This means a lot in SharePoint development. As we cannot deploy our solutions or assemblies to the server, the only possible way of development is remote development. SharePoint has provided numerous client-side APIs, REST APIs to connect to the SharePoint site remotely and perform the work.
End of Server Side Development?
There are two major scenarios to consider while developing the solutions for SharePoint irrespective of whether it is OnPremise or Online version.
Point 1 – Future compatibility of your solution
While developing the solutions for SharePoint OnPremise, we can use the full trusted farm solutions by making use of most server-side APIs. There is nothing absolutely wrong in it. But, what are the CONS of this approach?
- The server-side code is version dependent. That means the same code might not work for the next version of SharePoint or the APIs used might get deprecated.
- The server-side code needs to be tested every time after the cumulative updates to the server.
- How to migrate this code when the business decision demands SharePoint version upgrade or moving to cloud (SharePoint Online)?
Commonly used SharePoint Client Side Development Scenarios
To have the solutions developed in future ready manner, here are few approaches being commonly used by SharePoint developers.
Approach 1 – SharePoint Framework (SPFx)
Although SPFx launched recently, it attracted the attention of all developers. SPFx offers easy development option for Modern sites in SharePoint. Microsoft has started to support SharePoint framework based development on SharePoint 2016 OnPremise environment by releasing Feature pack 2 and are promoting the development using SPFx on both OnPremise and Online environments. Microsoft has also announced that SharePoint Framework will be an integral part of the new OnPremise version of SharePoint i.e. SharePoint 2019. SPFx development is purely based on HTML and JavaScript, which offers faster performance.
Approach 2 – Client Side Object Model (CSOM)
CSOM offers remote APIs to connect to SharePoint environment and perform the operations. It is generally used to perform CRUD operations with SharePoint.
Approach 3 – Client-Side JSOM
JavaScript Object Model (JSOM) supports performing operations remotely against SharePoint using JavaScript. JSOM is used widely by web developers.
Approach 4 – Content Editor (CEWP) and Script Editor WebParts
Content Editor (CEWP) and Script Editor WebParts are more close the SharePoint developers. These WebParts are used very commonly to perform an operation on a single page. These can be effectively used to add HTML content on SharePoint page, as well as running scripts for any DOM (Document Object Model) manipulation on SharePoint page.
Although heavy usage of these webparts brings in the governance issues, these webparts are most popular in SharePoint developer community.
Approach 5 – PowerShell
The PowerShell scripting tool also offers APIs to connect to local as well as remote SharePoint and perform the complex tasks. Initially, PowerShell was of only SharePoint Administrator’s favorite tool. However, over the time it catched the attention of developers too.
Approach 6 – REST APIs
REST APIs offers to perform basic CRUD operations against SharePoint objects such as lists, libraries, and sites. REST APIs can be combined with any of the above-mentioned approaches to achieve the certain functionality in SharePoint. SharePoint out of the box supports a vast range of REST APIs for developer needs.
Approach 7 – SharePoint Designer (SPD)
SPD is being used since ages now. The SharePoint Designer tool allows to connect to SharePoint environment remotely and customize it. SharePoint Designer is the obvious choice for developers to customize SharePoint forms, develop workflows, copy or move the documents.
Approach 8 – JS Link
JS Link supports customizing rendering of list views and list forms. This is replacing the approach of directly adding content or script editor webparts on-page and helped bring some governance around how JavaScript can be injected to SharePoint site.
Approach 9 – Graph APIs
Microsoft Graph provides unified APIs to securely connect to Office 365 applications including SharePoint Online and fetch the information. Graph APIs are not yet available on the OnPremise version of SharePoint.
Approach 10 – Use of supporting infrastructure
SharePoint development can be effectively combined with additional supporting infrastructure like MS Flow, Power Apps, Power BI, MS Azure, etc.

SharePoint 2013 Hosting – HostForLIFE.eu : How To Read SharePoint TermStore (Managed Metadata) Using REST API?
Jul 5th
SharePoint itself provides a REST API for each site you create. It is such wonderful thing to help the developers manipulate maximum areas of SharePoint like accessing lists, settings, users, user groups, navigation, etc. through the application that you built. Since there are some restrictions and threshold limits are always there in SharePoint to improve performance we cannot access some areas of SharePoint through Rest API. But still it is possible to access it by using SharePoint’s old web service methodology (until Microsoft deprecated it).
Let’s see the workaround to use SharePoint’s old web service methodology to get the TermStore Data with step by step instructions.
Step 1
Create a Managed Metadata field in any List and map the respective term set item with it, like below.
Step 2
Now, using REST API get the field information of the Managed Metadata column which you have created in the previous step so we could be able to get the SspId and TermSetId in the field XML of the list.
Rest API Url : {HostUrl}/_api/Web/Lists/getbytitle(‘{ListName}’)/fields/getbytitle(‘{FieldInternalName}’)?$select=SspId,TermSetId
The output will be like below: (SspId and TermSetId were highlighted)
Note – Since we need only these two values, I have queried only those fields in ODATA query $select=SspId,TermSetId in above url, if you want to read all field information, you can use ,*.
Step 3
Now, by passing these SspId and TermSetId, we need to make a SOAP call to invoke SharePoint web service to get the Term Set Data. Here, we are going to post the input data in XML format so please mention the content-type in the headers as “text/xml” along with the authorization headers.
The post body will look like below. Replace the highlighted values with respective ids.
WebService URL: {HostUrl}/_vti_bin/taxonomyclientservice.asmx?op=GetTermSets
Request Body
Finally, we will get the expected output in XML format and parse the XML to deserialize API response, sample output format is mentioned below.
SharePoint 2013 Hosting – HostForLIFE.eu : Update SharePoint List Items Using REST API
Jun 28th
Here is the detailed documentation for the SharePoint list items and their features. There are multiple ways to update the list item, here I am sharing the REST API Code.
Steps to update the SP List Item
Follow the below listed steps to update an item.
Step 1
Create one JS file or you can use the Content Editor Web Part.
Step 2
Below is the API to get the particular list item using Item ID, you can browse this URL in the browser to check whether the API is working or not.
https://sharepoint.com/_api/web/lists/GetByTitle(‘samplelist’)/items/getbyid(1)
Note
Replace your list name with “samplelist”.
Step 3
Refer to the jQuery in your HTML file or CEWP.
Use the below code to update the item in a SharePoint list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
'use strict'; ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js"); function initializePage() { var siteURL; var itemsArray = []; // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model $(document).ready(function() { var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/"; UpdateListItem(); }); //Retrieve list items from sharepoint using API function UpdateListItem() { siteURL = _spPageContextInfo.webAbsoluteUrl; console.log("from top nav - " + siteURL); var apiPath = siteURL + "/_api/lists/getbytitle(''samplelist'')/items/getbyid(1)"; $.ajax({ url: apiPath, type: "POST", headers: { Accept: "application/json;odata=verbose" }, data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:”Ur input " } ", async: false, success: function(data) { alert("Item updated successfully"); }, eror: function(data) { console.log("An error occurred. Please try again."); } }); } } |
In this blog, we have explored how to update a particular item in the SharePoint list using REST API. Happy coding.
SharePoint 2013 Hosting :: How To Remove Empty Folders In Sharepoint Library Using PnP Powershell
Jun 21st
A SharePoint library is a location on a site where you can upload, create, update, and collaborate on files with team members. To remove an empty folder from the library is difficult since we need to go to each and every library and identify whether it is empty or not. Then, we have to remove it from the library. To automate this process, I used Powershell scripting because it is easy to parse through each and every library using PNP library. So it is easy to identify and remove the empty folders in SharePoint library
Prerequisite
Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands.
Connect to Site
Connect to SharePoint site using Connect-PnPOnline cmdlet. The required parameters are,
-Url
The SharePoint site URL (Eg: https://hubflysoft.sharepoint.com/sites/Hubfly)
The following code snippet helps to connect SharePoint sites.
1 2 3 |
$siteurl="https://<tenant-name>.sharepoint.com" Connect-PnPOnline -Url $siteurl |
Get Web Instance using Get-PnPWeb
$web = Get-PnPWeb
The Get-PnPWeb cmdlet actually has its own Recurse option, and you could use that if you want to rather than doing your own recursion.
Get User Context using Get-PnPContext
$context = Get-PnPContext
The Get-PnPContext returns a Client Side Object Model context. This command is very handy and it returns the current context. You might need context because it might be the case you need to save the current context. By switching between two sites you need this.
Get folders from the library using Get-PnPFolder
1 |
$folder = Get-PnPFolder -RelativeUrl "Shared Documents" |
The Get-PnPFolder returns the folder called ‘Shared Documents’ which is located in the root of the current web.
Get all subfolders and remove empty folders
Using the context we need to load all files, folders, and Parent folder like below code snippet
- $files = $folder.Files
- $context.Load($folder.Files)
- $context.Load($folder.Folders)
- $context.Load($folder.ParentFolder)
- $context.ExecuteQuery()
We can find the folder is empty by the following conditions,
- Check if the files count is equal to zero
- Check if the folders count is equal to zero
And remove the empty folders using below PS script
1 2 3 4 5 6 7 8 9 10 11 12 |
Remove - PnPFolder if ($folder.Files.Count - eq 0 - and $folder.Folders.Count - eq 0 - and(($folder.Name - notmatch 'Document') - and($folder.Name - notmatch $libraryName))) { $path = $folder.ParentFolder.ServerRelativeUrl.Substring($web.ServerRelativeUrl.Length) Write - Host "Removing folder " $folder.ServerRelativeUrl.Substring($web.ServerRelativeUrl.Length) Remove - PnPFolder - Folder $path - Name $folder.Name - Recycle - Force $folders_list += $folder.Name + ", " + $folder.ServerRelativeUrl } Write - Host "Searching for empty folders. Please wait..." $folders_list = GetAllSubFolders $folder $context Write - Host $libraryName 'Completed' |
I hope you learned how to remove empty folders and files in the SharePoint library programmatically using PnP PowerShell scripting. The operations mentioned above are tested on SharePoint Online environment. Feel free to leave a comment below, if you need any assistance.