How can download attachment file in Microsoft Dynamics AX using DocumentHandlingService and C#(API)?

         public FileResult fileDownload(long  docRefRecId,string fileName)
        {           
            byte[]                                             fileByte;
            CallContext                                    context = new CallContext();
            DocumentHandlingServiceClient  client    = new DocumentHandlingServiceClient();
            DocumentFileDataContract           contract;
 
            client.ClientCredentials.Windows.ClientCredential.Domain     = ClientCredential_Domain;
            client.ClientCredentials.Windows.ClientCredential.UserName = ClientCredential_UserName;
            client.ClientCredentials.Windows.ClientCredential.Password   = ClientCredential_Password;
            context.Company = "***";
            contract = client.getFile(context, docRefRecId);
            fileByte = System.Convert.FromBase64String(contract.Attachment);
            
            FileContentResult result = new FileContentResult(fileByte, "application/octet-stream") 
            {
                FileDownloadName = fileName
            };
            
            return result;           
           
        }

Comments

Popular posts from this blog

How to loop through enum in dynamics ax 2012 using x++

How to read from csv file in Dynamics AX 2012 Through X++

How to Create Transfer Journal in Dynamics AX 2012 Through X++