Hi i have a container that has multiple records (lines)
I want to be able to send it to azure blob as csv
I'm assuming i need to convert the container to sth that can be accepted by azure blob
So what should i do exactly?
Do you mean attaching it to a table record D365FO when document management is configured to store attachments in Azure blob storage, or sending it to your own blob storage (independent on D365FO)?
Hi Martin,
My own blob storage. (however i would like to know the difference between the two options now that you've mentioned it)
What do you have in the container? Do I understand correctly that it's a list of strings? If so, you need to create CSV from this container before you can store CSV to a file. CommaStreamIo looks like the right class for this purpose.
Azure Storage offers a .NET API that you can call via .NET Interop from X++. You need CloudBlobClient class, in particular. With this knowledge, you can find examples by searching for D365FO and CloudBlobClient in your favourite search engine.
If you worked with document management, you would simply use Docu* classes in AX (e.g. DocumentManagement::attachFile()).
How can i convert the container to CSV?
I've seen an example where they do a while loop on a record and use io.writeExp
However is there a way to convert this contsiner directly to CSV? Using streamIO
Yes, it is possible. You seemed to overlook my suggestion: CommaStreamIo class.
Hi martin,
No i didn't overlook it. By saying streamIo.. I mean commaStreamIo.
So when u mentioned it i read about it.
My question was should i loop through the container? Or is there a way i can pass the container and it will convert it to CSV?
In ax12, the old service used commaTextIo
By using the method Write and passing container to it.
What should i do to see the file after using write method?
Also what's the difference between using commaTextIo and CommaStreamIo?
Please remember that I still don't know what you have in the container, therefore I can't say much about how you should process it. I can only assume that you want to do something with each element, therefore you'll indeed need to iterate the container to get elements one by one. But if you just wanted to create lines (because you already have lines content ready), you could do that with con2str(). Or maybe you have something else is in the container and you need to do something completely different.
Why do you want to "see the file"? I thought you want to write it to a blog, not to display it.
CommaStreamIO writes data to a stream, which you can pass to CloudBlockBlob.UploadFromStream(), for example. CommaTextIo writes to a file on disk.
Hi Matrin,
Thanks alot. yeah my container has string values.
What i did is, while filling each container i used commaStreamIo write method and i was able to receive the file successfully to azure blob ( it was a quick test). Here's what i did:
contianer lines; CommaStreamIo comma = CommaStreamIo::constructForWrite(); comma.outFieldDelimiter(","); str fileName = "Test.csv" comma.writeExp(lines); // assume lines is filled System.IO.Stream stream = comma.getStream(); 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(BlobContainer); stream.Position=0; Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cloudBlockBlob = cont.GetBlockBlobReference(fileName); cloudBlockBlob.UploadFromStream(stream,null,null,null);
Good! It seems that the problem is resolved. Please don't forget verify answer(s).
By the way, you can greatly simplify your code by utilizing the 'using' statement. Like this:
using System.IO; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Auth; using Microsoft.WindowsAzure.Storage.Blob; class MyClass { void export() { container lines; CommaStreamIo comma = CommaStreamIo::constructForWrite(); comma.outFieldDelimiter(','); str fileName = 'Test.csv'; comma.writeExp(lines); // assume lines is filled Stream stream = comma.getStream(); stream.Position = 0; StorageCredentials storageCredentials = new StorageCredentials(StorageAccountName, StorageKey); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer cont = blobClient.GetContainerReference(BlobContainer); CloudBlockBlob cloudBlockBlob = cont.GetBlockBlobReference(fileName); cloudBlockBlob.UploadFromStream(stream, null, null, null); } }
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
CA Neeraj Kumar 1,882
André Arnaud de Cal... 794 Super User 2025 Season 2
Sohaib Cheema 525 User Group Leader