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;
}
{
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
Post a Comment