最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

D365: Download multiple files in X++

网络文摘 William 44浏览 0评论

Purpose:

Demonstrate how can download multiple files in X++.

Application:

Dynamics 365 for Finance and Operations

Business requirement:

Business requirement is to let users download multiple files using a single browser session.

Solution:

We can use the code below to download multiple files using a single browser session.

Code

class ATLAS_Vend_File_Export
{
	private void exportFile(TextStreamIo _file, Filename _fileName)
	{
		System.IO.StreamReader reader;
		System.IO.Stream stream;
		str fileContent;
		
		stream = _file.getStream();
		stream.Position = 0;

		reader = new System.IO.StreamReader(stream);
		fileContent = reader.ReadToEnd();

		File::SendStringAsFileToUserNewTab(fileContent, _fileName);
	}
}
[ExtensionOf(classStr(File))]
final class ATLAS_File_Extension
{
    public static void SendStringAsFileToUserNewTab(str content, str fileName, System.Text.Encoding encoding = System.Text.Encoding::get_UTF8(), ClassName fileUploadStrategyClassName = classstr(FileUploadTemporaryStorageStrategy))
    {
        System.Byte[] byteArray = encoding.GetBytes(content);
        System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

        File::SendFileToUserNewTab(stream, fileName, fileUploadStrategyClassName);
    }

    public static void SendFileToUserNewTab(System.IO.Stream stream, str fileName, ClassName fileUploadStrategyClassName = classstr(FileUploadTemporaryStorageStrategy))
    {
        Browser br = new Browser();
        str downloadUrl;
        
        downloadUrl = File::SendFileToTempStore(stream, fileName, fileUploadStrategyClassName, true);
        if (downloadUrl != "")
        {
            br.navigate(downloadUrl, true, false);
        }
        else
        {
            warning("@ApplicationPlatform:DownloadFailed");
        }
    }

}
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址