Skip to main content
May 12, 2025

SharePoint File to Onestream

  • May 12, 2025
  • 2 replies
  • 0 views

Hello!

I'm trying to import a SharePoint file into OneStream using a business rule. I've not found any documentation/comments which are helpful. Does anyone have any ideas on how this can be done? 

Thanks! 

2 replies

May 12, 2025

A requirement like this isn't something you'll find in the OneStream docs.  I would use the SharePoint REST API to access and transfer files.  Here's something to get you started.  You'll need some familiarity with asynchronous operations also.

using System.Net.Http.Headers;

public async Task DownloadSharePointFileAsync(string siteUrl, string serverRelativeFilePath, string localFilePath, string accessToken)
{
    using var client = new HttpClient();
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
    var encodedPath = Uri.EscapeDataString(serverRelativeFilePath);
    var requestUrl = $"{siteUrl}/_api/web/getfilebyserverrelativeurl('{encodedPath}')/$value";

    using var response = await client.GetAsync(requestUrl);
    response.EnsureSuccessStatusCode(); 
    using var fileStream = File.Create(localFilePath);
    await response.Content.CopyToAsync(fileStream);
}


//Example
string siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite";
string filePath = "/sites/yoursite/Shared Documents/Report.xlsx";
string localPath = "C:\\Downloads\\Report.xlsx";
string token = await GetAccessTokenAsync(); // Your own token retrieval method

await DownloadSharePointFileAsync(siteUrl, filePath, localPath, token);

 

cap08Author
May 12, 2025

Hi Robb, 

Thanks for the starting point!