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");)
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).
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156