AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.07.2022, 13:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
dynamicsaxinsight: D365FO: Read CSV file from Azure File Share
Источник: https://dynamicsaxinsight.wordpress....re-file-share/
==============

Purpose:

The purpose of this post is to demonstrate how we can read a CSV file from Azure File Share in X++.

Application:

Dynamics 365 Finance and Operations

Prerequisites:
  • Azure file storage account must be configured in Azure Portal
  • File shares must be configured under this Azure file storage account
  • Access permissions must be configured for this Azure file storage account
Disclaimer:

This post is only for sharing knowledge. Do not use this code as is in a Production environment.

Business requirement:

Read a CSV file from Azure file share.

Solution:

Please find the code below to read a CSV file from Azure File Share. The code reads ABN numbers from a CSV file. The file has only a single column of ABN numbers with a single number per line.

Code

using Microsoft.Azure;using Microsoft.WindowsAzure.Storage;using Microsoft.WindowsAzure.Storage.Blob;using Microsoft.WindowsAzure.Storage.File;class MAKCloudStorageFileManager{ #File #define.delimiterField(',') public static void main(Args _args) { #OCCRetryCount System.IO.MemoryStream memoryStream; System.String storageAccountName; System.String keyValue; CloudStorageAccount storageAccount; CloudFileClient fileClient; CloudFileShare fileShare; CloudFileDirectory fileDirectoryRoot; CloudFileDirectory fileDirectory; CloudFile file; TextStreamIo textStreamIo; VendTable vendTable; VATNum vendABN; Counter counter; container rec; storageAccountName = "AzureStorageAccountName"; keyValue = "KeyValueString"; var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccountName, keyValue); storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true); fileClient = storageAccount.CreateCloudFileClient(); fileShare = fileClient.GetShareReference('AzureFileShareName'); if (fileShare.Exists(null, null)) { fileDirectoryRoot = fileShare.GetRootDirectoryReference(); fileDirectory = fileDirectoryRoot.GetDirectoryReference("Folder/Subfolder"); if (fileDirectory.Exists(null, null)) { file = fileDirectory.GetFileReference('File.csv'); if (file.Exists(null, null)) { memoryStream = new System.IO.MemoryStream(); file.DownloadToStream(memoryStream, null, null, null); textStreamIo = TextStreamIo::constructForRead(memoryStream); try { if (textStreamIo) { if (textStreamIo.status()) { throw Global::error("@SYS52680"); } textStreamIo.inFieldDelimiter(#delimiterField); textStreamIo.inRecordDelimiter(#delimiterCRLF); counter = 0; while (!textStreamIo.status()) { rec = textStreamIo.read(); if (conLen(rec)) { vendABN = conPeek(rec, 1); info(strFmt("%1", vendABN)); } } } } catch (Exception::Error) { error("An error occured. Please contact your system administrator."); } } } } }}
We can use Microsoft Azure Storage Explorer to browse files stored in Azure File Share or Azure Blob Containers.

You can run the class by using the runnable class URL below.

https://devaos.axcloud.dynamics.com/...ageFileManager


Источник: https://dynamicsaxinsight.wordpress....re-file-share/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dynamicsaxinsight: Read CSV file in X++ Blog bot DAX Blogs 0 20.10.2020 14:12
sertandev: Empowering D365 FO service endpoints with Azure API Management service Blog bot DAX Blogs 0 15.05.2019 22:11
emeadaxsupport: Connecting Retail Components on an External Computer to the Microsoft Dynamics AX R3 Azure Lifecycle Services Demo Virtual Machine Blog bot DAX Blogs 0 28.06.2014 00:13
wiki.dynamicsbook: Changes Made in Navision Attain 3.60 Blog bot Dynamics CRM: Blogs 0 02.09.2008 13:23
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 12:41.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.