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

Community site session details

Session Id :

Download an external file from Azure blob storage in D365 FO X++

Muhammad Uzair Shah Profile Picture Muhammad Uzair Shah 201

Hi folks, 

This post will be useful in scenario where an external file is stored in Azure blob storage and users wants to download that external file without having it stored in D365 FO database. 

Requirement:

Recently, I came across a requirement where I had to access the external file from Azure blob storage and then download that external file for the user from D365 FO application although the file doesn't even exist in D365 FO database. 

Solution:

Below is the code snippet of the solution that can be used as an example to download an external file for the users.

class ExternalFileDownload
{
    public static void main(Args _args)
    {
        str url;
        System.Net.HttpWebRequest httpRequest;
        System.Net.HttpWebResponse httpResponse;
        CLRObject clro;
        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
        Browser browser = new Browser();
        url = "https://[azureblobstorageurloftenant].blob.core.windows.net/temporary-file/{81D4B98A-1989-4B13-B056-684FE6AA86C7}/CustGroupPackage_340228B4-1D45-4DC9-9931-5C4900457149_DMFPackage.zip?sv=2014-02-14&sr=b&sig=1uHDh1D/qDScyDXE8rPA7HfLgTCnleYd0cPp/Ckmwwg=&st=2022-06-14T16:14:49Z&se=2022-06-14T17:19:49Z&sp=r";
        clro = System.Net.WebRequest::Create(url);
        httpRequest = clro;
        httpRequest.set_Method("GET");
        httpRequest.set_KeepAlive(true);
        httpRequest.set_ContentType("application/json");
        httpResponse = httpRequest.GetResponse();
        httpResponse.GetResponseStream().CopyTo(memoryStream);
        FileUploadTemporaryStorageResult result = File::SendFileToTempStore_GetResult(memoryStream, "Sample");
        browser.navigate(result.getDownloadUrl(), true);
        memoryStream.Close();
        httpResponse.Close();
    }
}

Comments

*This post is locked for comments