@Haider, Mustafa (Reigate) Welcome to the Microsoft Q&A platform and thank you for posting your question here.
As I understand you want to read files from folder on SharePoint Online using ADF. If this is not, please let me know.
To access files from subfolders in SharePoint Online using Azure Data Factory, you can create a dataset that points to the parent folder and then use a wildcard path to specify the subfolder and file name pattern.
Adding to that Azure Data Factory (ADF) cannot directly copy a folder or multiple files from SharePoint Online, but there are ways to do it. You need to add two steps to the pipeline compared to copying a single file:
- Get the list of files. You can do this manually by maintaining a list of file names in a text file, or you can use a Web Activity to call the SharePoint REST API to get the list of files.
- Use a ForEach Activity to loop through the list of file names and pass each file name to a Copy Activity. The base URL for the Copy Activity is slightly different than for copying a single file.
- Inside ForEach use Copy Data activity to read the files from the folder you selected in the dataset. You can use the wildcard characters to specify the file names or patterns. If you want to read all the CSV files in the Europe folder, you can use the following file path:
Europe/2023_01_01_*
.
Here's an example of how to set up the Copy Data activity to retrieve files from the Europe folder and transfer the data to the SQL Database.
{
"name": "CopyData",
"type": "Copy",
"inputs": [
{
"name": "SharePointDataset"
}
],
"outputs": [
{
"name": "SqlDatabaseDataset"
}
],
"copyBehavior": "PreserveHierarchy",
"source": {
"type": "SharePointOnlineSource",
"queryTimeout": "02:00:00",
"recursive": true,
"wildcardFileName": "*.csv",
"folderPath": "Europe"
},
"sink": {
"type": "AzureSqlDatabaseSink",
"writeBatchSize": 10000,
"writeBatchTimeout": "00:05:00",
"sqlWriterCleanupScript": "",
"allowPolyBase": true,
"polyBaseSettings": {
"rejectType": "Percentage",
"rejectValue": 10,
"useTypeDefault": true
}
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"columnMappings": "AutoMap"
},
"parallelCopies": 1,
"cloudDataMovementUnits": 0
}
Furthermore, the 'Copy file from SharePoint Online' operation uses Azure Active Directory (AAD) and service principal authentication, along with the SharePoint API, to fetch files.
Register SharePoint Application and Grant permission - https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad-app?tabs=dotnet#register-your...
You can find complete instructions on how to register an app and grant permissions in the prerequisites section here.
Please refer to this article for a better understanding Copy files from SharePoint
I hope this helps! Let me know if you have any further questions.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.