---
id: "T:cAlgo.API.File"
kind: "interface"
namespace: "cAlgo.API"
url: "https://help.ctrader.com/ctrader-algo/references/Utility/File/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# File (interface)

Represents a file.

Environments: Desktop supported · CLI supported · Cloud not supported.

- Cloud: Exists returns false; reads return empty string/array; writes and appends silently do nothing. No exception.

## Definition

```csharp
public interface File
```

Available since cAlgo.API 5.7.

## Remarks

You can use this as a parameter type to get direct read and write access to a file.

## Examples

C#:

```csharp
public partial class FileSample : Robot
{
    protected override void OnStart()
    {
        if (!TradesLog.Exists())
            TradesLog.WriteAllText("Time,Symbol,Side" + Environment.NewLine);

        Positions.Opened += args => TradesLog.AppendAllText($"{Server.Time:O},{args.Position.SymbolName},{args.Position.TradeType}{Environment.NewLine}");
        Print("Logging trades to {0} ({1} bytes)", TradesLog.Name, TradesLog.Size);
    }
}
```

Python:

```python
def on_start(self):
    if not api.TradesLog.Exists():
        api.TradesLog.WriteAllText("Time,Symbol,Side\n")
    api.Positions.Opened += self.on_position_opened
    api.Print(f"Logging trades to {api.TradesLog.Name} ({api.TradesLog.Size} bytes)")

def on_position_opened(self, args):
    position = args.Position
    api.TradesLog.AppendAllText(f"{api.Server.Time},{position.SymbolName},{position.TradeType}\n")
```

config.json:

```json
{
  "AccessRights": "None",
  "Parameters": [
    {
      "Name": "TradesLog",
      "DisplayName": "Trades Log",
      "Type": "File"
    }
  ]
}
```

## Methods

- `void AppendAllLines(string[] contents)` — Appends lines to file. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/AppendAllLines/index.md)
- `void AppendAllLines(string[] contents, EncodingType encodingType)` — Appends lines to file that has a specified encoding. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/AppendAllLines/index.md)
- `void AppendAllText(string contents)` — Append text to file. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/AppendAllText/index.md)
- `void AppendAllText(string contents, EncodingType encodingType)` — Appends text to file that has a specified encoding. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/AppendAllText/index.md)
- `bool Exists()` — Returns True if File exists otherwise False. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/Exists/index.md)
- `byte[] ReadAllBytes()` — Reads the contents of the file into a byte array. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/ReadAllBytes/index.md)
- `string ReadAllText()` — Reads all the text in the file. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/ReadAllText/index.md)
- `string ReadAllText(EncodingType encodingType)` — Reads all the text in the file that has a specified encoding. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/ReadAllText/index.md)
- `byte[] ReadBytes(int offset, int count)` — Reads a sequence of bytes from the file. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/ReadBytes/index.md)
- `string[] ReadLines()` — Reads the lines of file. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/ReadLines/index.md)
- `string[] ReadLines(EncodingType encodingType)` — Reads the lines of file that has a specified encoding. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/ReadLines/index.md)
- `void WriteAllBytes(byte[] bytes)` — Overwrites file content with passed bytes. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/WriteAllBytes/index.md)
- `void WriteAllText(string contents)` — Overwrites file content with passed text content. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/WriteAllText/index.md)
- `void WriteAllText(string contents, EncodingType encodingType)` — Overwrites file content with passed text content that has a specified encoding. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/WriteAllText/index.md)
- `void WriteBytes(byte[] bytes, int offset, int count)` — Writes a chunk of data to file specific position. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/WriteBytes/index.md)

## Properties

- `DateTime CreationTime {get;}` — Gets the creation time of the file. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/CreationTime/index.md)
- `string Extension {get;}` — Gets the extension part of the file name, including the leading dot '.' even if it is the entire file name, or an empty string if no extension is present. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/Extension/index.md)
- `DateTime LastAccessTime {get;}` — Gets the time the current file was last accessed. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/LastAccessTime/index.md)
- `DateTime LastWriteTime {get;}` — Gets the time when the current file was last written to. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/LastWriteTime/index.md)
- `string Name {get;}` — Gets file name without path. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/Name/index.md)
- `long Size {get;}` — Gets file size in bytes. [details](https://help.ctrader.com/ctrader-algo/references/Utility/File/Size/index.md)

