create. Text file creation   [3.1.5]

^file::create[format;name;content]
^file::create[
format;name;content;options]   [3.4.0]

Constructs an object of class
file, with specified name and content.

Format defines format of created file. For now it can be only text.
Options-hash, in which you can specify $.charset[charset] or $.content-type[...] [3.4.1]

Note: if there is a need to save file to server disk, there is simple way:
^string.save[…].

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

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"?>
<products>
   <product id="1" name="
Can be &quot;Quoted&quot;"/><product id="2" name="Johnson&amp;Johnson"/>
</products>


Copyright © 1997–2011 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 26.02.2011