<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to upload files from databricks to sharepoint? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-upload-files-from-databricks-to-sharepoint/m-p/114948#M44998</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/149365"&gt;@eenaagrawal&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;There isn't a specific built-in integration in Databricks to directly interact with Sharepoint. However, you can accomplish this by leveraging libraries like Office365-REST-Python-Client, which enable interaction with Sharepoint's REST API.&lt;BR /&gt;Here are the steps you can follow:&lt;/P&gt;&lt;P&gt;1. Set Up a Service Principal in Azure (if using SharePoint Online)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Register an app in Azure Active Directory to obtain a Client ID and Client Secret.&lt;/LI&gt;&lt;LI&gt;Assign the appropriate permissions to the app for accessing your SharePoint resources.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;2. Install Required Libraries&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In your Databricks notebook, install the necessary Python libraries:&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Code: %pip install Office365-REST-Python-Client&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;3. Generate Access Token&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You will need an access token to interact with SharePoint. Authenticate using the registered app's IDs (from Azure).&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;Example:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from office365.runtime.auth.authentication_context import AuthenticationContext&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from office365.sharepoint.client_context import ClientContext&lt;BR /&gt;&amp;nbsp;&amp;nbsp; site_url = " "&amp;nbsp; &amp;nbsp;client_id = " "&amp;nbsp;&amp;nbsp; client_secret = " "&amp;nbsp;&amp;nbsp; context_auth = AuthenticationContext(site_url)&amp;nbsp;&amp;nbsp; if context_auth.acquire_token_for_app(client_id, client_secret):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ctx = ClientContext(site_url, context_auth)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Authentication successful")&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(context_auth.get_last_error())&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;4. Read the File in Databricks&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Read or prepare the file you want to upload to Sharepoint within Databricks. For instance:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; file_path = "/dbfs/path/to/your/file.csv"with open(file_path, "rb") as file:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_content = file.read()&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;5. Upload File to SharePoint&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Specify the SharePoint document library or folder and upload the file:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; target_folder_url = "/sites/yoursite/Shared Documents/folder_name"&amp;nbsp;&amp;nbsp; file_name = "file.csv"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; target_folder = ctx.web.get_folder_by_server_relative_url(target_folder_url)&amp;nbsp;&amp;nbsp; file_upload = target_folder.upload_file(file_name, file_content)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ctx.execute_query()&lt;BR /&gt;&amp;nbsp;&amp;nbsp; print(f"File {file_name} uploaded successfully.")&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;6. Verify the Uploaded File&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;After uploading, you can query your SharePoint site to confirm the file exists in the intended location&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Wed, 09 Apr 2025 11:18:01 GMT</pubDate>
    <dc:creator>SP_6721</dc:creator>
    <dc:date>2025-04-09T11:18:01Z</dc:date>
    <item>
      <title>How to upload files from databricks to sharepoint?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-upload-files-from-databricks-to-sharepoint/m-p/114895#M44980</link>
      <description>&lt;P&gt;I required steps.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 05:32:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-upload-files-from-databricks-to-sharepoint/m-p/114895#M44980</guid>
      <dc:creator>eenaagrawal</dc:creator>
      <dc:date>2025-04-09T05:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload files from databricks to sharepoint?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-upload-files-from-databricks-to-sharepoint/m-p/114948#M44998</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/149365"&gt;@eenaagrawal&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;There isn't a specific built-in integration in Databricks to directly interact with Sharepoint. However, you can accomplish this by leveraging libraries like Office365-REST-Python-Client, which enable interaction with Sharepoint's REST API.&lt;BR /&gt;Here are the steps you can follow:&lt;/P&gt;&lt;P&gt;1. Set Up a Service Principal in Azure (if using SharePoint Online)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Register an app in Azure Active Directory to obtain a Client ID and Client Secret.&lt;/LI&gt;&lt;LI&gt;Assign the appropriate permissions to the app for accessing your SharePoint resources.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;2. Install Required Libraries&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In your Databricks notebook, install the necessary Python libraries:&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Code: %pip install Office365-REST-Python-Client&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;3. Generate Access Token&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You will need an access token to interact with SharePoint. Authenticate using the registered app's IDs (from Azure).&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;Example:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from office365.runtime.auth.authentication_context import AuthenticationContext&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from office365.sharepoint.client_context import ClientContext&lt;BR /&gt;&amp;nbsp;&amp;nbsp; site_url = " "&amp;nbsp; &amp;nbsp;client_id = " "&amp;nbsp;&amp;nbsp; client_secret = " "&amp;nbsp;&amp;nbsp; context_auth = AuthenticationContext(site_url)&amp;nbsp;&amp;nbsp; if context_auth.acquire_token_for_app(client_id, client_secret):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ctx = ClientContext(site_url, context_auth)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Authentication successful")&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(context_auth.get_last_error())&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;4. Read the File in Databricks&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Read or prepare the file you want to upload to Sharepoint within Databricks. For instance:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; file_path = "/dbfs/path/to/your/file.csv"with open(file_path, "rb") as file:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_content = file.read()&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;5. Upload File to SharePoint&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Specify the SharePoint document library or folder and upload the file:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; target_folder_url = "/sites/yoursite/Shared Documents/folder_name"&amp;nbsp;&amp;nbsp; file_name = "file.csv"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; target_folder = ctx.web.get_folder_by_server_relative_url(target_folder_url)&amp;nbsp;&amp;nbsp; file_upload = target_folder.upload_file(file_name, file_content)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ctx.execute_query()&lt;BR /&gt;&amp;nbsp;&amp;nbsp; print(f"File {file_name} uploaded successfully.")&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;6. Verify the Uploaded File&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;After uploading, you can query your SharePoint site to confirm the file exists in the intended location&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:18:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-upload-files-from-databricks-to-sharepoint/m-p/114948#M44998</guid>
      <dc:creator>SP_6721</dc:creator>
      <dc:date>2025-04-09T11:18:01Z</dc:date>
    </item>
  </channel>
</rss>

