• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
        • File Action Invoker Namespace
        • File.copy Action
        • File.readBytes Action
        • File.readLines Action
        • File.readText Action
        • File.writeBytes Action
        • File.writeLines Action
        • File.writeText Action
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

File.writeText Action

Format
CS.File.writeText(path := ..., text := ...ʃ, encoding := ...ʅ)
ArgumentDescriptionTypes / Required
pathThe path of the file to write.string
required
textThe text to write.string
required
encodingThe encoding to use while writing the text.
The default value is "UTF-8".
string
not required
Description
The File.writeText action writes a string, text, to a text file specified as path. If a file already exists at path, it is overwritten with the new contents.
The encoding argument allows you specify how the contents of the file are encoded to text. Options include:
  • "ANSI": The contents are encoded as part of the Windows code page.
  • "UTF-8": The contents are encoded as UTF-8 and written without a byte order mark (BOM).
  • "UTF-8-BOM": The contents are encoded as UTF-8 and written with a three-byte BOM.
Return Value
The action returns undefined.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form or if the file cannot be created or fully written.
Example (CSPro)
// read the text stored in readme.txt
string fileText = CS.File.readText(path := "readme.txt");

// write the text in uppercase form
CS.File.writeText(path := "readme (uppercase).txt", text := toupper(fileText));
See also: File Action Invoker Namespace, File.readText Action, File.writeBytes Action, File.writeLines Action, File.write Function