web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Connecting to Azure File Share (Not Blob Storage) through AL Code

(0) ShareShare
ReportReport
Posted on by

Is it possible to connect to Azure File Share through AL code and import data from a file on the file share into a journal in BC? I have tried to use the Rest APIs with no luck (https://docs.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api). The particular issue I keep running into is authorization. I'm doing authorization with a Shared Key and following the authorization guidelines based on MS documentation (https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key).

Code Sample:

trigger OnRun()
    var
        requestMethod: Text;
        request: HttpRequestMessage;
        RequestHeader: HttpHeaders;
        hhtpres: HttpResponseMessage;
        canonicalizedResource: Text;
        canonicalizedHeaders: Text;
        urlPath: Text;
        client: HttpClient;
        content: HttpContent;
        authorizationHeader: Text;
        stringToSign: Text;
        msVersion: Text;
        cha: Char;
        contenttype: Text;
        contentLength: Integer;
        SharedKey: Text;
        dateInRfc1123Format: Text;
        EncryptionManagement: Codeunit "Cryptography Management";
        uri: Text;
        fileName: Text;
    begin
        cha := 10;
        msVersion := '2019-12-12';
        SharedKey := '';
        dateInRfc1123Format := GetUTCDateTimeText();
        requestMethod := 'GET';
        fileName := 'abc.xlsm';
        urlPath := '//';
        CanonicalizedResource := StrSubstNo('/%1/%2', '', '//');
        canonicalizedHeaders := 'x-ms-date:'   dateInRfc1123Format   Format(cha)  
                                'x-ms-version:'   msVersion;



        stringToSign := (requestMethod   Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         Format(cha)  
                         canonicalizedHeaders   Format(cha)  
                         canonicalizedResource);

        authorizationHeader := 'SharedKey :'   EncryptionManagement.GenerateBase64KeyedHashAsBase64String(stringToSign, SharedKey, 2);

        uri := 'https://.file.core.windows.net///';

        request.SetRequestUri(uri);
        request.Method := requestMethod;
        RequestHeader.Clear();
        request.GetHeaders(RequestHeader);
        RequestHeader.Add('Authorization', authorizationHeader);
        RequestHeader.Add('x-ms-date', dateInRfc1123Format);
        RequestHeader.Add('x-ms-version', msVersion);

        client.Send(request, hhtpres);

        if not hhtpres.IsSuccessStatusCode then
            Error(FORMAT(hhtpres.HttpStatusCode)   ': '   hhtpres.ReasonPhrase)
        else
            Message(FORMAT(hhtpres.HttpStatusCode)   ': '   hhtpres.ReasonPhrase);
    end;

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Never tried directly from AL. Personally I'm using an Azure Function called from AL and the logic to access the file share is handled in the Azure Function itself.

    Are you using shared keys?The shared key normally should be passed in the url.

  • Zay Profile Picture
    on at

    Thanks for the reply Stefano.

    Do you have any links or samples I could review? Also is there any other way besides Azure File Share to accomplish the goal of automatically reading file and importing it into a BC journal with no user interaction?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans