/

 

The manual

Self-training

Experimentation

Contact

 

Language

File manipulation

The 'File' type

In Storga, files are 'File' type variables.
In the rest of this document, we assume that the variable 'f' has the type 'File', for example:

var File f

Get the file name:

var Str s := f name

Change the file name:

f name := "aute.txt"

Get file date:

var DateTime dt := f datetime

Change the date of the file (with the current time in the example below):

f datetime := datetime

Get file size:

var Int s := f size

Obtain the display mode of the file block:

var Str s := f display

Change the display mode of the file block:

f display := "open"

The keywords that define the display mode of a file block are (several can be used separated by spaces):

Keyword

Visual effect

open

The file can be opened by clicking on it.

view

The contents of the file are displayed directly by Storga.

download

A 'Download' button is added, which allows you to download the contents of the file.

upload

An 'Upload' button is added, which allows you to change the content of the file.

Get the title associated with the file:

var Str s := f title

Associate a title to the file:

f title := "Le logo de l'entreprise"

Get the summary associated with the file:

var Str s := f resume

Associate a summary to the file:

f resume := "Version n°3[lf]Créée le 12 novembre 2013 par Lorent"

Organize files

Browse the different file blocks of the current page or sheet

each_file f
  ...

each_file f sheet
  ...

Store the file in a page, a sheet, an email

new_file f ...

The position options that can be used by 'new_file' are the same as those used by 'new_form'.

Move it

move_file f ...

The position options usable by 'move_file' are the same as those usable by 'new_form'.

Delete it

delete_file f

Handle a file as a whole

Make a file from Storga content

write_file f "fichier.csv" "options_de_formatagefrom report "identifiant_storga_de_l_etat"
write_file f "formulaire.pdf" "print" from form "identifiant_storga_du_formulaire
write_file f "fichier.csv" "options_de_formatagefrom dataware d

The export type is defined from the extension in the file name. The following extensions are defined:

Extension

Content export mode

.txt

As plain text.

.csv

As a CSV file (supposes that we are exporting a report and not a page or a form)

.html

As HTML formatted text

.odt

As an editable office file.

.pdf

As a file with final and fixed layout.

If you export a Storga form to PDF, you can use the keyword 'print' in formatting options to get the print version of the document.

From: Hubert Tonneau   2015-08-14 16:31:36

Préciser les options de mise en forme (bas de page pour les fichiers PDF, etc)

From: Hubert Tonneau   2015-08-14 16:32:53

Préciser l'option 'overwrite' pour l'export d'un état, qui permet de forcer les champs de filtrage.

Syntaxe obsolète

Jusqu'en 2021, on utilisait une instruction 'export_as_file' au lieu de l'instruction 'write_file'.

f := export_as_file "identifiant_storga_de_la_page_ou_du_formulaire" "fichier.html" "options_de_formatage"

Instead of the identifier of a Storga block, 'export_as_file' can take a data of type 'Dataware' as its first argument. In this case, the possible export formats are .csv and .json.

Convert a file

The 'convert_file' function is very useful for converting between various file formats, for example from .doc to .pdf

The simplest syntax is:

var File f2 := convert_file f "foo.pdf" ""

In case of failure in the conversion, it may be interesting to recover the error code in a variable, here 'e':

var File f2 := convert_file f "foo.pdf" "" error (var Str e)

For information, the old syntax was:

var Str err := convert_file f "foo.pdf" "" (var File f2)

Exchange a file with a server

See the client part of the article 'HTTP and FTP interface'
      

Provide to user

Cause a file download:

download_file f

A scenario for using this function is in a form, the user presses a button which causes the production of a file and offers the user to download its content.

From: Loic Dumas   2024-02-17 12:56:02

open_file f
Permet de provoquer directement l'ouverture du fichier par une application tiers.

Read or write the contents of a file

The end of this document specifies the functions available to read or write certain types of files. Obviously, unfortunately, Storga does not provide functions allowing to read all the types of files, nor even all the possible operations on the types of supported files. The supported file types are:

   •   

text

   •   

CSV

   •   

JSON

   •   

XML

   •   

Spreadsheet

   •   

ZIP

   •   

PDF

Read or write a text file

Read or write a CSV file

Creation of an XML, Json and possibly other file by substitution in an example file

Reading an XML or JSON file

Read / write to a spreadsheet file

Lire le texte dans un fichier image ou un fichier PDF (fonction OCR)

Composition / decomposition of ZIP or PDF files