• <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.readText Action

Format
s = CS.File.readText(path := ...ʃ, encoding := ...ʅ)
ArgumentDescriptionTypes / Required
pathThe path of the file to read.string
required
encodingThe encoding to use to decode the file's text.
The default value is "UTF-8".
string
not required
Description
The File.readText action reads a file, specified as path, as text, returning the entire file's content as a single string.
The encoding argument allows you specify how the contents of the file are decoded to text. There are few cases where this may be necessary, as the default of reading UTF-8 text will generally meet the needs of most users. Options include:
  • "ANSI": The contents are decoded as part of the Windows code page.
  • "UTF-8": The contents are decoded as UTF-8, regardless of whether there is a byte order mark (BOM).
  • "UTF-8-BOM": The contents are decoded as UTF-8, regardless of whether there is a BOM.
Return Value
The action returns a string containing the file's content.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form or if the file does not exist or cannot be read.
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.writeText Action, File.readBytes Action, File.readLines Action, File.read Function