create. File creation   [3.1.5]

^file::create[format;name;string or file]
format;name;string or file;options]   [3.4.0]
^file::create[string;extended options]   [3.4.2]
^file::create[file;extended options]   

Constructs an object of class
file, with specified name and content.
While creating an object in
text format the constructor normalizes all end of line (EOL) characters.   [3.4.2]

Format defines format of created file.
Until version 3.4.2 the method was able to create an object in
text format only.
Options-hash, in which you can specify $.from-charset[charset] or $.to-charset[charset] or $.content-type[...] [3.4.1] [3.4.5]
Extended options-hash, in which besides regular options you can specify $.name[file name], $.mode[format].

Note: if there is a need to save file to server disk, there is simple way:
Note: before version 3.4.5, there was no parameter with the encoding from which to convert the data (
from-charset), and the parameter with the encoding into which to convert the data was called not to-charset, but simply charset.

Example of export data in XML format
connect[connection string]{
table::sql{select product_id, name from products}]
$file[^file::create[text;export.xml;^untaint[xml]{<?xml version="1.0" encoding="$request:charset"?>
^{<product id="$products.product_id" name="$"/>}

When this document is opened then file
export.xml is created and browser suggests visitor to save it.
Sample result:

<?xml version="1.0" encoding="UTF-8"?>
   <product id="1" name="
Can be &quot;Quoted&quot;"/><product id="2" name="Johnson&amp;Johnson"/>

Copyright © 1997–2017 Art. Lebedev Studio | Last updated: 20.04.2017