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, ...
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");)

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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

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
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans