Friday, March 13, 2015

The Multi-File download Cookbook

Lists of technical and non-technical NAV blogsThe Dynamics NAV dev middle

trendy sample isn't a sample however a "cookbook" that indicates the way to use the FileManagement library to download assorted files as a .zip file through Microsoft Dynamics NAV in a method that works on all kinds of shoppers.

summary

The aim of this pattern is to enable the clients to download distinctive info as a zip file instead of downloading separately.  On the Microsoft Dynamics NAV internet client, here is the favorite means of providing distinct files seeing that it is likely one of the net patterns and we can not use the File management codeunit to area info silently on the laptop.

Description

When producing experiences that includes assorted, and constantly an unknown number of information, the developer will ought to address the down load which also depends on the customer the person is on. The issue is that the Microsoft Dynamics NAV home windows customer has entry to the consumer's file system, whereas the internet client does not. Following web instructions, and the incontrovertible fact that customer-facet .net is not attainable in web customer, you could't provoke multiple downloads which requires the developer respond to the category of client. In some browsers it is feasible to down load data one-by means of-one in the net customer by using a ascertain dialog, however this is a hack and will not be used.

To solve this problem, a time-honored down load mechanism is used that's customer elegant event when numerous information need to be downloaded. For the web client, the data are compressed the usage of ZIP, and for the windows client the files are downloaded at once to the file device.

The sample is usable for all objects that output distinct files and is purchasable in each home windows client and internet customer.

utilization

The sample carries two steps: 1) Gathering the info and a couple of) downloading the file(s)

For first step includes a loop that goes during the info that needs to be downloaded. if it is on the internet customer, the files are brought to a zip archive server-side the usage of a naming conference defined by way of the mixing characteristic GetSeriesFileName. This feature takes a filename and quantity, and transforms it to unique names following a significant deterministic pattern e.g. prepend an integer earlier than the file extension. The same characteristic is used when the temporary files are created server facet, so the data can also be discovered deterministically later. This eliminates the need for storing filenames and due to this fact permits an arbitrary variety of info. The second integration feature: GetTotalNumberOfFiles, returns the whole variety of data generated during the facts processing and makes the sample in a position to deal with an arbitrary variety of info.

The second step is the in fact download of file(s). For the internet customer this contains closing the ZIP achieve and downloading by way of the standard download handler that works in the net customer. For the Win customer, the info are saved at once to the client during step one.

Code 1: File loop shows an instance implementation of this pattern. ServerFileName is generated firstly of the report/codeunit, and is the bottom for GetSeriesFilename. The file it really is truly written to during data processing is kept in yet another variable which holds the output from GetSeriesFilename on the latest file number. notice; the instance code will best create a zipper file if there basically are distinctive data to be downloaded. 

examine greater on the NAV Design Patterns Wiki....

most excellent regards,

Martin Dam at Microsoft construction core Copenhagen

No comments:

Post a Comment