Copy Files from SharePoint Site content to Azure Blob using Logic Apps

118 Views Asked by At

I Have multiple Document Library in my Sharepoint site content. I have to iterate each document library and copy the files along with Folder structure in Azure Blob.

Right side flow - I have created a workflow using "Get files(Properties only)" action but it take one library at a time. and for all the document library i have to use multiple get Files action in parallel

How can i iterate multiple Document library and use "Get files(Properties only)" action to achive this task. or if any other alternative to achieve this ?

Workflow-

enter image description here

1

There are 1 best solutions below

0
Ikhtesam Afrin On

I have used the below workflow to get the libraries and lists from SharePoint and then iterated over the each libraries and lists. Lastly uploading the files to Blob storage.

Workflow-

enter image description here enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Code-

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "For_each_1": {
                        "actions": {
                            "Condition": {
                                "actions": {
                                    "Create_blob_(V2)": {
                                        "inputs": {
                                            "body": "@body('Get_file_content_using_path')",
                                            "headers": {
                                                "ReadFileMetadataFromServer": true
                                            },
                                            "host": {
                                                "connection": {
                                                    "referenceName": "azureblob"
                                                }
                                            },
                                            "method": "post",
                                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files",
                                            "queries": {
                                                "folderPath": "/demo-container",
                                                "name": "@{items('For_each_1')?['{FullPath}']}",
                                                "queryParametersSingleEncoded": true
                                            }
                                        },
                                        "runAfter": {
                                            "Get_file_content_using_path": [
                                                "SUCCEEDED"
                                            ]
                                        },
                                        "runtimeConfiguration": {
                                            "contentTransfer": {
                                                "transferMode": "Chunked"
                                            }
                                        },
                                        "type": "ApiConnection"
                                    },
                                    "Get_file_content_using_path": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "referenceName": "sharepointonline"
                                                }
                                            },
                                            "method": "get",
                                            "path": "/datasets/@{encodeURIComponent(encodeURIComponent('*************'))}/GetFileContentByPath",
                                            "queries": {
                                                "inferContentType": true,
                                                "path": "@{items('For_each_1')?['{FullPath}']}",
                                                "queryParametersSingleEncoded": true
                                            }
                                        },
                                        "type": "ApiConnection"
                                    }
                                },
                                "else": {
                                    "actions": {}
                                },
                                "expression": {
                                    "and": [
                                        {
                                            "equals": [
                                                "@items('For_each_1')?['{isFolder}']",
                                                false
                                            ]
                                        }
                                    ]
                                },
                                "type": "If"
                            }
                        },
                        "foreach": "@body('Get_items_')?['value']",
                        "runAfter": {
                            "Get_items_": [
                                "SUCCEEDED"
                            ]
                        },
                        "type": "Foreach"
                    },
                    "Get_items_": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "referenceName": "sharepointonline"
                                }
                            },
                            "method": "get",
                            "path": "/datasets/@{encodeURIComponent(encodeURIComponent('*************'))}/tables/@{encodeURIComponent(encodeURIComponent(items('For_each')?['DisplayName']))}/items",
                            "queries": {
                                "viewScopeOption": "RecursiveAll"
                            }
                        },
                        "type": "ApiConnection"
                    }
                },
                "foreach": "@body('Get_all_lists_and_libraries')?['value']",
                "runAfter": {
                    "Get_all_lists_and_libraries": [
                        "SUCCEEDED"
                    ]
                },
                "type": "foreach"
            },
            "Get_all_lists_and_libraries": {
                "inputs": {
                    "host": {
                        "connection": {
                            "referenceName": "sharepointonline"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('***********'))}/alltables"
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_a_HTTP_request_is_received": {
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "kind": "Stateful"
}

I am able to get the expected output.

enter image description here

enter image description here