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

Save ER file to Azure File share instead of downloading it in local download folder

(2) ShareShare
ReportReport
Posted on by 6,478
Hello,
I have created another post on this subject few days ago, but decided to create this one too for better explanations.
our goal is to save Customer payment xml file directly to the Azure File Share.
Currently it is downloaded automatically in the local download folder and then we manually upload the file into Azure, which takes much time.
We have seen the post below, but it may work only if the generate Payment doesn't use the ER.
 
In Azure File share we will have 2 separate folders. 
1 with currency EUR and another for any other currency.
Is there Possibility to achieve it with some setup, or writting a code will be 100% necessary?
We need it to be in one go, meaning, by clicking Oks on Generate Payment dialog box, file should be saved directly into Azure File Share.
 
One thing to mention also is that, currently, as mentioned the file is downloaded locally in download file and it is a .zip file, which contains xml file. We need this xml file, not the .zip file to be placed in Azure file share.
 
This is the class and method where it is determined if it should go to ER or not. In our case it will be always ER.
 
Thanks!
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    300,917 Super User 2025 Season 2 on at
    Hi Johnny,

    Creating duplicate posts for the same question is not the correct way. Instead, you can provide additional information to your original question, 
    I think this is the other question. Save file directly to Azure storage account file share directory (dynamics.com)
    You updated it today. You could also provide the details you now wrote in this post. Having two posts on the same topic is not recommended. At least, now you are confusing me about the status and your attempts so far.
  • Arcadi  Profile Picture
    794 on at
    Hello Johnny, 
     
    About getting the XML instead of the ZIP is very easy, in the ER workspace you go to electronic reporting destinations, create a new one for your format with the ZIP node without destination and the XML with a destination, for example: 
     
     
    About sending them to Azure file share is more difficult, but not impossible. Off the top off my head I can think on two options:
     
    - Sending them to a Sharepoint and using Azure logic apps to move them to Azure file share. Just select as destination for the XML "Archive" and the File Type (Organization Administration / document Types) should be pointing to Sharepoint:
     
     
     
    Or you could using X++ create a new destination pointing to Azure file share (It's possible, I've created it for Azure blob storage): 
     
     
  • Johnny Profile Picture
    6,478 on at
    Hello Arcadi,
    Thanks for the link.
    I have started creating the new destination, but it does not mention anything regarding the Azure, so I'm not really sure how to continue here.
    You mentioned you have done to for Azure Blob.
    Could you give more details? Did you just do everything that is described in the link you posted and then in the new "Path" field added the Azure Blob folder?
    How does it understand the credentials for Azure, etc?
  • Arcadi  Profile Picture
    794 on at
    Hi Johnny
     
    Yeah you could start by Microsoft example but the destination is different of course. In my case I read documentation of how to connect to an azure blob with C# and adapted it to X++. You also have the option to work directly with C#... For both options there is a lot of documentation.
     
    How our solution works, we hide the connection string in a key vault, we use the standard D365FO form of key vaults to connect to it and then on the destination we have a couple of fields, a lookup to select the record of the key vaults table and another for the blob name. But that's just one of the multiple ways you could implement your solution. 
     
     
  • Johnny Profile Picture
    6,478 on at
    Hi Arcadi,
    I'm still struggling with it : )))
    I also tried creating class library, but if I create it with .net standard 2.1 or .net 8.0, then I can't reference it with my x++ project.
    If I change it to net46 (which is same as x++ project), then the code does not work.
     
    But, I have found some examples of uploading ER file directly to file share, but it also does not work in my case.
     
     
    Here I do not get any error, but file is still not being uploaded to File share folder and instead it is still downloaded locally in my download folder.
    I have done setup of Document type and ER destination parameters and have set it to Azure Storage.
    Then I used and adapted the code above to a standard class below, which executes the ER files.
     
    [SubscribesTo(classStr(ERDocuManagementEvents), staticDelegateStr(ERDocuManagementEvents, attachingFile))]
    public static void ERDocuManagementEvents_attachingFile(ERDocuManagementAttachingFileEventArgs _args)
     
    First question would be under what framework version should I create my .net class library to reference it correctly to my x++ project?
    Second question would be, if you have ever used / extended "ERDocuManagementEvents_attachingFile"?
     
    Thanks
  • Johnny Profile Picture
    6,478 on at
    Update:
    This approach works perfectly, but it is to upload the file in Blob container.
    If I try to addapt it so file is uploaded to File share, then I get a "Bad Request" error.
     
    Here is my code for File Share which throws Bad request errors
     
    StorageCredentials  storageCredentials  = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(credentialTable.AccountName, azKey); //Auth
    CloudStorageAccount storageAccount      = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
    CloudFileClient     fileClient          = storageAccount.CreateCloudFileClient();
    CloudFileShare      root                = fileClient.GetShareReference('fileShareRoot'); //name of the file share
    
    if(!root.Exists(null, null))
    {
        return Checkfailed('Azure storage parameters are not set up correctly.');
    }
    
    CloudFileDirectory fileDirectory = root.GetRootDirectoryReference();
    
    fileDirectory.GetDirectoryReference('testFolder'); //folder in file share where the file should be uploaded
    
    CloudFile cloudFile = fileDirectory.GetFileReference(_args.getAttachmentName());
    
    if (_fileStream.CanSeek)
    {
        _fileStream.Seek(0, System.IO.SeekOrigin::Begin);
    }
    
    cloudFile.UploadFromStream(_fileStream, null, null, null); //here the Bad Request error is thrown
     
    Here is my Code for Blob container, which works perfectly:
     
    StorageCredentials  credentials     = new StorageCredentials(credentialTable.AccountName, azKey);
    CloudStorageAccount storageAccount  = new CloudStorageAccount(credentials, true);
    CloudBlobClient blobClient          = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer rootContainer    = blobClient.GetContainerReference('testcon'); //Blob container name
    if(!rootContainer.Exists(null, null))
    {
        return Checkfailed('Azure storage parameters are not set up correctly.');
    }
    
    CloudBlobDirectory directory = rootContainer.GetDirectoryReference('testdir'); // folder name under container where file is uploaded
    CloudBlockBlob blockBlob =                directory.GetBlockBlobReference(strFmt(_args.getAttachmentName()));
    if (_fileStream.CanSeek)
    {
        _fileStream.Seek(0, System.IO.SeekOrigin::Begin);
    }
    blockBlob.UploadFromStream(_fileStream, null, null, null);
     
    I could not understand, what is going wrong in File Share case.
     
    Thanks!
  • Johnny Profile Picture
    6,478 on at
    Update 2:
    The error came from _args.getAttachmentName() in case of file share. Looks like it can't process the file names with spaces
    CloudFile cloudFile = fileDirectory.GetFileReference(_args.getAttachmentName());
    In case of Blob container, spaces in file name isn't an issue.
     
    CloudBlockBlob blockBlob =                directory.GetBlockBlobReference(strFmt(_args.getAttachmentName()));
     
    It there possibility to kind of ignore white spaces in file name?
  • Johnny Profile Picture
    6,478 on at
    The problem was caused by the file name with ':' in it. Have modified it with strReplace and now it works as expected

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 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans