D365/AX7:Upload & Save a File in Azure Blob Storage using X++

Using Azure Blob Storage In Scheduled Tasks | Notificare

Requirement: Saving a file and uploading memory stream of file in Azure BLOB Storage account using X++ in Microsoft Dynamics 365 finance and operations

Prerequisites: Azure BLOB Storage account & its connection string

Classes Used:

CloudBlobDirectory,CloudBlobClient,CloudBlobContainer,CloudStorageAccount,CloudBlockBlob

Sample Code:

using Microsoft.WindowsAzure.Storage;
 Using Microsoft.WindowsAzure.Storage.Blob;
 class RunnableClassBlobStorageUpload
 {
     /// 
     /// Runs the class with the specified arguments.     /// 

     /// 
The specified arguments.
     public static void main(Args _args)
     {
         System.Byte[] reportBytes = new System.Byte[0]();
         System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
         reportBytes = enc.GetBytes("YOUR XML STRING/TEXT");
         System.IO.MemoryStream stream = new System.IO.MemoryStream(reportBytes);
         CloudBlobDirectory  cloudBlobDirectory;
         CloudBlobClient  cloudBlobClient;
         CloudBlobContainer  cloudBlobContainer;
         CloudStorageAccount  cloudStorageAccount;
         cloudStorageAccount  = CloudStorageAccount::Parse("DefaultEndpointsProtocol=https;AccountName=blobstorageazureservice;AccountKey=Q3zap5G1iU2GRyDQAmRF4z4hDMpPeJtj3AGfeOraiyPqFgzYrH3h59JIgFGSJX6sqTn/nbszsJHvrNz7KwfZKA==;EndpointSuffix=core.windows.net");
         cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
         cloudBlobContainer  = cloudBlobClient.GetContainerReference("files");
         CloudBlockBlob  CloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("Txt.Txt");
         CloudBlockBlob.UploadFromStream(stream, null, null, null);
 }
 }

One thought on “D365/AX7:Upload & Save a File in Azure Blob Storage using X++”

Leave a Reply