Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to fetch the file from Azure blob storage and save as an attachment using X++

(0) ShareShare
ReportReport
Posted on by 5

X++ code in D365 F&O for fetching the file from azure blob storage and attaching it to respective table like "PurchTable" as an attachment .

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;


class FetchAndUploadAttachment
{
public static void attachFileFromBlobStorage(Common _common, Filename _fileName, str _notes = '')
{
Microsoft.Dynamics.AX.Framework.FileManagement.IDocumentStorageProvider storageProvider;
PersonnelIntegrationStorageAccountConnectionString azureStorageKey = personnelIntegrationConfiguration::find().editEncryptDecryptStorageAccountConnectionString(false);
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount::Parse(azureStorageKey);
var blobcli = storageAccount.CreateCloudBlobClient();
Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer cont = blobcli.GetContainerReference("File path of azure blob storage folder");
CloudBlockBlob cloudBlockBlob = cont.GetBlockBlobReference(_fileName);
System.IO.Stream memory = cloudBlockBlob.OpenRead(null,null,null);
Filename attachmentName = System.IO.Path::GetFileNameWithoutExtension(_fileName);
str fileContentType = System.Web.MimeMapping::GetMimeMapping(_fileName);
DocuRef docuRef;

docuRef = DocumentManagement::attachFileToCommon(_common, DocuType::typeFile(), memory, _fileName, fileContentType, attachmentName, _notes);

if (docuRef.RecId)
{
info("Attached the file to the respective table record");
}

}

}

Note :  Call this mehod from whereever you want based on your requirements(FetchAndUploadAttachment::attachFileFromBlobStorage(purchtable, "FileName.pdf", "this is pdf file");)

  • Martin Dráb Profile Picture
    231,856 Most Valuable Professional on at
    RE: How to fetch the file from Azure blob storage and save as an attachment using X++

    Hi Mohammed, what is your question? If you want to share information rather than dicuss something, it's better to use a blog instead of a discussion forum.

    Also, your code is difficult to read, because it lacks indentation. Use Insert > Code (in the rich formatting view) to avoid this problem.

    And please ask questions about D365FO in a D365FO forum (such as Dynamics 365 Finance Forum).

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,041 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,856 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans