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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to upload file in Azure blob storage from D365FO on specify folder

(3) ShareShare
ReportReport
Posted on by 230
Hi Team,
 
Using the below code i am generating the log file and here my requirement is i have to upload this log file to azure blob storage in a specify folder
public void createData()
{
   CommaStreamIo       io = CommaStreamIo::constructForWrite();
   CustTable           custTable;
   const str           fileName = "customers.log";
   str 		           folderName = "\local\iftablepurgelogs"  

   io.writeExp(['Account Number', 'Customer' , 'Currency', 'Data Area']);
  
        while select custTable
            where custTable.DataAreaId == 'USMF'
        {
            io.writeExp([custTable.AccountNum, custTable.name(), custTable.Currency, custTable.DataAreaId]);
        }
    System.IO.Stream stream = iO.getStream();
}

Please help to write a code to upload log file in azure blob storage on a specify folder.
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,447 Super User 2025 Season 2 on at
    Hi,
     
    I think you can send your file using business events and power automate to store them to azure blob store.
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Vahid Ghafarpour Profile Picture
    12,200 Super User 2025 Season 2 on at
    After putting data into stream you can use BlobServiceClient to upload to blob, something like this:
     
     
    private void UploadToBlobStorage(Stream stream, string fileName, string folderName)
        {
            string connectionString = "your_connection_string"; // Replace with your Azure Blob Storage connection string
            string containerName = "your_container_name"; // Replace with your container name
            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
            // Combine folder name and file name to create the blob name
            string blobName = $"{folderName}/{fileName}";
            BlobClient blobClient = containerClient.GetBlobClient(blobName);
            // Upload the stream to the blob
            blobClient.Upload(stream, new BlobHttpHeaders { ContentType = "text/plain" });
            Console.WriteLine($"File uploaded to Blob Storage: {blobName}");
        }
     
  • Vahid Ghafarpour Profile Picture
    12,200 Super User 2025 Season 2 on at
    If any of these replies answer your question
    ** Please don't forget to close up the thread by Like and verify it as an answer if it is helpful **
     
  • CU21091228-0 Profile Picture
    230 on at
    Is this X++ code, actually in x++ we are not using Console.WriteLine and getting below error.
     
     
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Please follow this link. Using this you just need to pass stream as a parameter which uploads file to azure blog storage.
     
     
    Let us know if this helps.
  • Martin Dráb Profile Picture
    237,987 Most Valuable Professional on at
    VaHiX's code indeed isn't X++; it looks like C#.
  • Layan Jwei Profile Picture
    8,118 Super User 2025 Season 2 on at
    Hi,
     
    You could find a lot of code online. But some libraries are deprecated so make sure to replace them with new ones.
     
    For example, instead of using Microsoft.Azure.Storage.Blob then maybe use Azure.Storage.Blobs
     
    Check out Microsoft article and check what is deprecated and what is its replacement 
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
  • Suggested answer
    Layan Jwei Profile Picture
    8,118 Super User 2025 Season 2 on at
    Hi,
     
    You could try sth like this ( you can make the code better). But it was announced that some libraries are deprecated so make sure to replace them with new ones if that's the case
      System.Exception        ex;
      try
      {
          Microsoft.WindowsAzure.Storage.Auth.StorageCredentials  storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("StorageAccountName", "StorageKey");
         Microsoft.WindowsAzure.Storage.CloudStorageAccount      storageAccount      = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
         var                                                     blobcli             = storageAccount.CreateCloudBlobClient();
         Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer  cont                = blobcli.GetContainerReference("Container");
    
         stream.Position = 0;
    
         Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob      cloudBlockBlob      = cont.GetBlockBlobReference("fileName");
         cloudBlockBlob.UploadFromStream(stream,null,null,null);
      }
      catch(ex)
      {
         throw error(strFmt("UploadFailed", ex.Message));
      }
     

     
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
     
  • Suggested answer
    Layan Jwei Profile Picture
    8,118 Super User 2025 Season 2 on at
    Hi,
     
    You could try sth like this ( you can make the code better). But it was announced that some libraries are deprecated so make sure to replace them with new ones if that's the case
     
     System.Exception        ex;
      try
      {
          Microsoft.WindowsAzure.Storage.Auth.StorageCredentials  storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("StorageAccountName", "StorageKey");
         Microsoft.WindowsAzure.Storage.CloudStorageAccount      storageAccount      = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
         var                                                     blobcli             = storageAccount.CreateCloudBlobClient();
         Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer  cont                = blobcli.GetContainerReference("Container");
         stream.Position = 0;
         Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob      cloudBlockBlob      = cont.GetBlockBlobReference("fileName");
         cloudBlockBlob.UploadFromStream(stream,null,null,null);
      }
      catch(ex)
      {
         throw error(strFmt("UploadFailed", ex.Message));
      }

    Check out Microsoft article and check what is deprecated and what is its replacement:
    https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/fin-ops/get-started/removed-deprecated-features-platform-updates#migration-from-deprecated-libraries--windowsazurestorage-and-microsoftazurestorage-to-azurestorageblobs
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Vahid Ghafarpour Profile Picture
    12,200 Super User 2025 Season 2 on at
     

    ** Please don't forget to close up the thread here by Like and verify it as an answer if it was solved **

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 467 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans