Notifications
Announcements
No record found.
internal final class ITSGetAttachedFileRunnabl{ /// <summary> /// Class entry point. The system will call this method when a designated menu /// is selected or when execution starts and this class is set as the startup class. /// </summary> /// <param name = /_args/>The specified arguments.</param> public static void main(Args _args) { DocuRef docuref; ITSGetFileFromDocMgmtInVariousFormats runnable = ITSGetFileFromDocMgmtInVariousFormats::construct(); select docuref where docuref.RecId == 68719599267; runnable.readfromDocuRefAttachments(docuref); }}
using Microsoft.Dynamics.ApplicationPlatform.Services.Instrumentation;using Microsoft.DynamicsOnline.Infrastructure.Components.SharedServiceUnitStorage;using Microsoft.Dynamics.AX.Framework.FileManagement;using Microsoft.WindowsAzure.Storage;Using Microsoft.WindowsAzure.Storage.Blob;internal final class ITSGetFileFromDocMgmtInVariousFormats{ str docfiletype; Microsoft.Dynamics.AX.Framework.FileManagement.IDocumentStorageProvider storageProvider; Public void readfromDocuRefAttachments(DocuRef _docuRef) { Blobdata blobContainer; AsciiStreamIo file; container record; str downloadUrl; // Grant clrinterop permission. new InteropPermission(InteropKind::ClrInterop).assert(); if (_docuRef.isValueAttached()) { var docuValueloc = _docuRef.docuValue(); downloadUrl = docuValueloc.Path; if (!downloadUrl || docuValueloc.Type == DocuValueType::Others) { str accessToken = DocumentManagement::createAccessToken(_docuRef); downloadUrl = Microsoft.Dynamics.AX.Framework.FileManagement.URLBuilderUtilities::GetDownloadUrl(docuValueloc.FileId, accessToken); } storageProvider = Docu::GetStorageProvider(_docuRef.docuType(), false); var docContents = storageProvider.GetFile(docuValueloc.createLocation()); file = AsciiStreamIo::constructForRead(docContents.Content); // download file on browser file.read(); str displayUrl = DocumentManagement::getAttachmentPublicUrl(_docuref); Browser br = new Browser(); br.navigate(displayUrl); // To byte - working System.IO.StreamReader streamReader = new System.IO.StreamReader(docContents.Content); System.Byte[] bytes; System.Text.Encoding getUTF8 = System.Text.Encoding::get_UTF8(); //bytes = getUTF8.GetBytes(streamReader.ReadToEnd()); bytes = getUTF8.GetBytes(streamReader.ReadToEnd()); //info ('Byte ready'); // To memorystream System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes); //info ('stream ready'); // to binary and blob container Binary binaryData = Binary::constructFromMemoryStream(stream); //info ('binary ready'); if (binaryData) { blobContainer = binaryData.getContainer(); //info ('Container ready'); } // to base 64 str fileBase64Str = con2base64str(blobContainer); info (strFmt('base: %1', fileBase64Str)); //info (/Base64 ready/); DocuValue docuValue; select firstonly docuValue where docuValue.RecId == _docuRef.ValueRecId; info (strFmt('Original filename is %1', docuValue.originalFileName)); } } public static ITSGetFileFromDocMgmtInVariousFormats construct() { return new ITSGetFileFromDocMgmtInVariousFormats(); }}
internal final class ITSGetAttachedFileRunnabl { public static void main(Args _args) { DocuRef docuRef = DocuRef::findRecId(68719599267); ITSGetFileFromDocMgmtInVariousFormats::construct().readFromDocuRefAttachments(docuRef); } }
using Microsoft.Dynamics.ApplicationPlatform.Services.Instrumentation; using Microsoft.DynamicsOnline.Infrastructure.Components.SharedServiceUnitStorage; using Microsoft.Dynamics.AX.Framework.FileManagement; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Blob; internal final class ITSGetFileFromDocMgmtInVariousFormats { str docfiletype; Microsoft.Dynamics.AX.Framework.FileManagement.IDocumentStorageProvider storageProvider; public void readFromDocuRefAttachments(DocuRef _docuRef) { Blobdata blobContainer; if (_docuRef.isValueAttached()) { var docuValueloc = _docuRef.docuValue(); str downloadUrl = docuValueloc.Path; if (!downloadUrl || docuValueloc.Type == DocuValueType::Others) { str accessToken = DocumentManagement::createAccessToken(_docuRef); downloadUrl = Microsoft.Dynamics.AX.Framework.FileManagement.URLBuilderUtilities::GetDownloadUrl(docuValueloc.FileId, accessToken); } storageProvider = Docu::GetStorageProvider(_docuRef.docuType(), false); var docContents = storageProvider.GetFile(docuValueloc.createLocation()); AsciiStreamIo file = AsciiStreamIo::constructForRead(docContents.Content); // download file on browser file.read(); str displayUrl = DocumentManagement::getAttachmentPublicUrl(_docuref); Browser br = new Browser(); br.navigate(displayUrl); // To byte - working System.IO.StreamReader streamReader = new System.IO.StreamReader(docContents.Content); System.Byte[] bytes; System.Text.Encoding getUTF8 = System.Text.Encoding::get_UTF8(); bytes = getUTF8.GetBytes(streamReader.ReadToEnd()); // To memorystream System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes); // to binary and blob container Binary binaryData = Binary::constructFromMemoryStream(stream); if (binaryData) { blobContainer = binaryData.getContainer(); } // to base 64 str fileBase64Str = con2base64str(blobContainer); info (strFmt('base: %1', fileBase64Str)); DocuValue docuValue; select firstonly docuValue where docuValue.RecId == _docuRef.ValueRecId; info (strFmt('Original filename is %1', docuValue.originalFileName)); } } public static ITSGetFileFromDocMgmtInVariousFormats construct() { return new ITSGetFileFromDocMgmtInVariousFormats(); } }
DocuRef docuRef; select docuRef where docuRef.RecId == 68719599267; BitMap fileContents = DocumentManagement::getAttachmentAsContainer(docuRef); str fileBase64Str = con2base64str(fileContents); info (strFmt('base string: %1', fileBase64Str));
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 Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 660 Most Valuable Professional
André Arnaud de Cal... 549 Super User 2025 Season 2
Sohaib Cheema 307 User Group Leader