Sample code for 30+ languages & platforms
DataFlex

Azure File Service: List Shares

See more Azure Cloud Storage Examples

Sample code to list the file shares in an Azure storage account.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoRest
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Variant vAzAuth
    Handle hoAzAuth
    String sResponseStr
    Handle hoXml
    Handle hoLastMod
    Integer iNumShares
    Integer i
    Variant vDt
    Handle hoDt
    String sTemp1
    Integer iTemp1
    Integer iTemp2
    Integer iTemp3
    Boolean bTemp1

    Move False To iSuccess

    // Azure File Service Example: List all the file shares in a storage account.
    // See also: https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    // Connect to the Azure Storage Blob Service
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    // In this example, the storage account name is "chilkat".
    Get ComConnect Of hoRest "chilkat.file.core.windows.net" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Provide Azure Cloud credentials for the REST call.
    Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
    If (Not(IsComObjectCreated(hoAzAuth))) Begin
        Send CreateComObject of hoAzAuth
    End
    Set ComAccessKey Of hoAzAuth To "AZURE_ACCESS_KEY"
    // The account name used here should match the 1st part of the domain passed in the call to Connect (above).
    Set ComAccount Of hoAzAuth To "chilkat"
    Set ComScheme Of hoAzAuth To "SharedKey"
    Set ComService Of hoAzAuth To "File"
    // This causes the "x-ms-version: 2021-08-06" header to be automatically added.
    Set ComXMsVersion Of hoAzAuth To "2021-08-06"
    Get pvComObject of hoAzAuth to vAzAuth
    Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess

    // Note: The application does not need to explicitly set the following
    // headers: x-ms-date, Authorization.  These headers
    // are automatically set by Chilkat.

    // Send the GET request to list the shares.
    Get ComFullRequestNoBody Of hoRest "GET" "/?comp=list" To sResponseStr
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // When successful, the Azure Storage service will respond with a 200 response status code,
    // with an XML response body.

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        // Examine the request/response to see what happened.
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "response status code = " iTemp1
        Get ComResponseStatusText Of hoRest To sTemp1
        Showln "response status text = " sTemp1
        Get ComResponseHeader Of hoRest To sTemp1
        Showln "response header: " sTemp1
        Showln "response body (if any): " sResponseStr
        Showln "---"
        Get ComLastRequestStartLine Of hoRest To sTemp1
        Showln "LastRequestStartLine: " sTemp1
        Get ComLastRequestHeader Of hoRest To sTemp1
        Showln "LastRequestHeader: " sTemp1
        Procedure_Return
    End

    // Load the XML response for parsing.
    // An example of the response XML is shown below.
    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Get ComLoadXml Of hoXml sResponseStr To iSuccess

    Get ComGetXml Of hoXml To sTemp1
    Showln sTemp1

    // Here's a sample response:

    // <?xml version="1.0" encoding="utf-8" ?>
    // <EnumerationResults ServiceEndpoint="https://chilkat.file.core.windows.net/">
    //     <Shares>
    //         <Share>
    //             <Name>beardie</Name>
    //             <Properties>
    //                 <Last-Modified>Mon, 26 Jun 2017 21:24:57 GMT</Last-Modified>
    //                 <Etag>"0x8D4BCD9CBD872E5"</Etag>
    //                 <Quota>5120</Quota>
    //             </Properties>
    //         </Share>
    //         <Share>
    //             <Name>pip</Name>
    //             <Properties>
    //                 <Last-Modified>Mon, 26 Jun 2017 21:24:44 GMT</Last-Modified>
    //                 <Etag>"0x8D4BCD9C3D823D1"</Etag>
    //                 <Quota>5120</Quota>
    //             </Properties>
    //         </Share>
    //     </Shares>
    //     <NextMarker />
    // </EnumerationResults>

    // Let's iterate over the file shares
    Get Create (RefClass(cComCkDateTime)) To hoLastMod
    If (Not(IsComObjectCreated(hoLastMod))) Begin
        Send CreateComObject of hoLastMod
    End

    Get ComNumChildrenAt Of hoXml "Shares" To iNumShares
    Move 0 To i
    Get Create (RefClass(cComChilkatDtObj)) To hoDt
    If (Not(IsComObjectCreated(hoDt))) Begin
        Send CreateComObject of hoDt
    End
    While (i < iNumShares)
        Showln "---- Share " i " ----"
        Set ComI Of hoXml To i
        Get ComGetChildContent Of hoXml "Shares|Share[i]|Name" To sTemp1
        Showln "Name: " sTemp1
        Get ComGetChildContent Of hoXml "Shares|Share[i]|Properties|Last-Modified" To sTemp1
        Get ComSetFromRfc822 Of hoLastMod sTemp1 To iSuccess
        Get pvComObject of hoDt to vDt
        Send ComToDtObj To hoLastMod True vDt

        Get ComYear Of hoDt To iTemp1
        Get ComMonth Of hoDt To iTemp2
        Get ComDay Of hoDt To iTemp3
        Showln "Last-Modified YMD: " iTemp1 "," iTemp2 "," iTemp3
        Move (i + 1) To i
    Loop

    // Output for the above loop:

    // ---- Share 0 ----
    // Name: beardie
    // Last-Modified YMD: 2017,6,26
    // ---- Share 1 ----
    // Name: pip
    // Last-Modified YMD: 2017,6,26
    // 

    Showln "Success."


End_Procedure