# OpcFileStream Members

> Reference: Provides a Stream for a file node.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcFileStream</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx.client">Opc.UaFx.Client</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
<dt>Also in</dt>
<dd>Opc.UaFx.Client</dd>
</dl>

Inherits members from [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream), [MarshalByRefObject](https://learn.microsoft.com/dotnet/api/system.marshalbyrefobject).

## Constructors

### OpcFileStream

<span class="api-meta">3 overloads</span>

| Overload | Description |
|---|---|
| [OpcFileStream(OpcFileInfo, OpcFileMode)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#opcfilestream-opc-uafx-client-opcfileinfo-opc-uafx-opcfilemode) | Initializes a new instance of the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) class using the specified `file` and `mode`. |
| [OpcFileStream(OpcFileNodeContext, OpcFileMode)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#opcfilestream-opc-uafx-client-opcfilenodecontext-opc-uafx-opcfilemode) | Initializes a new instance of the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) class using the specified `context` and `mode`. |
| [OpcFileStream(OpcClient, OpcNodeId, OpcFileMode)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#opcfilestream-opc-uafx-client-opcclient-opc-uafx-opcnodeid-opc-uafx-opcfilemode) | Initializes a new instance of the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) class using the specified `client`, `fileNodeId` and `mode`. |

#### OpcFileStream(OpcFileInfo, OpcFileMode)

Initializes a new instance of the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) class using the specified `file` and `mode`.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcFileStream(OpcFileInfo file, OpcFileMode mode)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(file As OpcFileInfo, mode As OpcFileMode)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `file` | [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) | The [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) of the file node to access. |
| `mode` | [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) | The [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) to use to access the file node. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `file` is a null reference (Nothing in Visual Basic). |

#### OpcFileStream(OpcFileNodeContext, OpcFileMode)

Initializes a new instance of the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) class using the specified `context` and `mode`.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcFileStream(OpcFileNodeContext context, OpcFileMode mode)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(context As OpcFileNodeContext, mode As OpcFileMode)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `context` | [OpcFileNodeContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilenodecontext/) | The [OpcFileNodeContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilenodecontext/) of the file node to access. |
| `mode` | [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) | The [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) to use to access the file node. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `context` is a null reference (Nothing in Visual Basic). |

#### OpcFileStream(OpcClient, OpcNodeId, OpcFileMode)

Initializes a new instance of the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) class using the specified `client`, `fileNodeId` and `mode`.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcFileStream(OpcClient client, OpcNodeId fileNodeId, OpcFileMode mode)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(
    client As OpcClient,
    fileNodeId As OpcNodeId,
    mode As OpcFileMode)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `client` | [OpcClient](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/) | The [OpcClient](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/) to use to access the file node. |
| `fileNodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) of the file node to access. |
| `mode` | [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) | The [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) to use to access the file node. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `client` or `fileNodeId` is a null reference (Nothing in Visual Basic). |

## Properties

### CanRead

<span class="api-meta">override</span>

Gets a value indicating whether the current stream supports reading.

<div class="api-signature" data-lang="csharp">

```csharp
public override bool CanRead { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides ReadOnly Property CanRead As Boolean
```

</div>

**Property value**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the stream supports reading; otherwise the value false.

**Overrides**

[CanRead](https://learn.microsoft.com/dotnet/api/system.io.stream.canread)

**Remarks**

If the stream is closed, this property returns false.

### CanSeek

<span class="api-meta">override</span>

Gets a value indicating whether the current stream supports seeking.

<div class="api-signature" data-lang="csharp">

```csharp
public override bool CanSeek { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides ReadOnly Property CanSeek As Boolean
```

</div>

**Property value**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the stream supports seeking; otherwise the value false.

**Overrides**

[CanSeek](https://learn.microsoft.com/dotnet/api/system.io.stream.canseek)

**Remarks**

If the stream is closed, this property returns false.

### CanWrite

<span class="api-meta">override</span>

Gets a value indicating whether the current stream supports writing.

<div class="api-signature" data-lang="csharp">

```csharp
public override bool CanWrite { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides ReadOnly Property CanWrite As Boolean
```

</div>

**Property value**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the stream supports writing; otherwise the value false.

**Overrides**

[CanWrite](https://learn.microsoft.com/dotnet/api/system.io.stream.canwrite)

**Remarks**

If the stream is closed, this property returns false.

### File

Gets the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) used to determine the file accessibility and its size.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcFileInfo File { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property File As OpcFileInfo
```

</div>

**Property value**

[OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/)

The [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) used by the [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object.

### Handle

Gets a [SafeOpcFileHandle](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.safeopcfilehandle/) object that represents the file handle for the file that the current [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object encapsulates.

<div class="api-signature" data-lang="csharp">

```csharp
public SafeOpcFileHandle Handle { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Handle As SafeOpcFileHandle
```

</div>

**Property value**

[SafeOpcFileHandle](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.safeopcfilehandle/)

An object that represents the file handle for the file that the current [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object encapsulates or a null reference (Nothing in Visual Basic) then the file stream has been disposed of or closed.

### Length

<span class="api-meta">override</span>

Gets the length in bytes of the stream.

<div class="api-signature" data-lang="csharp">

```csharp
public override long Length { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides ReadOnly Property Length As Long
```

</div>

**Property value**

[Int64](https://learn.microsoft.com/dotnet/api/system.int64)

A long value representing the length of the stream in bytes.

**Exceptions**

| Exception | Condition |
|---|---|
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The stream has been disposed of. |

**Overrides**

[Length](https://learn.microsoft.com/dotnet/api/system.io.stream.length)

### Position

<span class="api-meta">override</span>

Gets or sets the position within the current stream.

<div class="api-signature" data-lang="csharp">

```csharp
public override long Position { get; set; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Property Position As Long
```

</div>

**Property value**

[Int64](https://learn.microsoft.com/dotnet/api/system.int64)

The current position within the stream.

**Exceptions**

| Exception | Condition |
|---|---|
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The stream has been disposed of. |

**Overrides**

[Position](https://learn.microsoft.com/dotnet/api/system.io.stream.position)

## Methods

### Close

<span class="api-meta">override</span>

Closes the current stream and releases any resources associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.

<div class="api-signature" data-lang="csharp">

```csharp
public override sealed void Close()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public NotOverridable Overrides Sub Close()
```

</div>

**Overrides**

[Close()](https://learn.microsoft.com/dotnet/api/system.io.stream.close)

**Remarks**

Attempts to manipulate the stream after the stream has been closed might throw an [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception).

### Flush

<span class="api-meta">override</span>

Clears all buffers for this stream and causes any buffered data to be written to the underlying device.

<div class="api-signature" data-lang="csharp">

```csharp
public override void Flush()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Sub Flush()
```

</div>

**Overrides**

[Flush()](https://learn.microsoft.com/dotnet/api/system.io.stream.flush)

### Read

<span class="api-meta">override</span>

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

<div class="api-signature" data-lang="csharp">

```csharp
public override int Read(byte[] buffer, int offset, int count)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Function Read(
    buffer As Byte(),
    offset As Integer,
    count As Integer) As Integer
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `buffer` | [Byte](https://learn.microsoft.com/dotnet/api/system.byte)[] | An array of bytes. When this method returns, the buffer contains the specified byte array with the values between `offset` and (`offset` + `count` - 1) replaced by the bytes read from the current source. |
| `offset` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The zero-based byte offset in `buffer` at which to begin storing the data read from the current stream. |
| `count` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The maximum number of bytes to be read from the current stream. |

**Returns**

[Int32](https://learn.microsoft.com/dotnet/api/system.int32)

The total number of bytes read into the `buffer`. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The sum of `offset` and `count` is larger than the `buffer` length. |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `buffer` is a null reference (Nothing in Visual Basic). |
| [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception) | The `offset` or `count` is negative. |
| [NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception) | The stream does not support reading. |
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The stream has been disposed of. |

**Overrides**

[Read(byte\[\], int, int)](https://learn.microsoft.com/dotnet/api/system.io.stream.read)

**Remarks**

Use the [CanRead](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#canread) property to determine whether the current instance supports reading.

### Seek

<span class="api-meta">override</span>

Sets the position within the current stream.

<div class="api-signature" data-lang="csharp">

```csharp
public override long Seek(long offset, SeekOrigin origin)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Function Seek(offset As Long, origin As SeekOrigin) As Long
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `offset` | [Int64](https://learn.microsoft.com/dotnet/api/system.int64) | A byte offset relative to the `origin` parameter. |
| `origin` | [SeekOrigin](https://learn.microsoft.com/dotnet/api/system.io.seekorigin) | A value of type [SeekOrigin](https://learn.microsoft.com/dotnet/api/system.io.seekorigin) indicating the reference point used to obtain the new position. |

**Returns**

[Int64](https://learn.microsoft.com/dotnet/api/system.int64)

The new position within the current stream.

**Exceptions**

| Exception | Condition |
|---|---|
| [NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception) | The stream does not support seeking. |
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The stream has been disposed of. |

**Overrides**

[Seek(long, SeekOrigin)](https://learn.microsoft.com/dotnet/api/system.io.stream.seek)

**Remarks**

Use the [CanSeek](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#canseek) property to determine whether the current instance supports seeking. Seeking to any location beyond the length of the stream is supported.

### SetLength

<span class="api-meta">override</span>

Sets the length of the current stream.

<div class="api-signature" data-lang="csharp">

```csharp
public override void SetLength(long value)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Sub SetLength(value As Long)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `value` | [Int64](https://learn.microsoft.com/dotnet/api/system.int64) | The desired length of the current stream in bytes. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The stream has been disposed of. |
| [NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception) | The stream does not support both writing and seeking. |

**Overrides**

[SetLength(long)](https://learn.microsoft.com/dotnet/api/system.io.stream.setlength)

**Remarks**

Use the [CanWrite](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#canwrite) property to determine whether the current instance supports writing, and the [CanSeek](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#canseek) property to determine whether seeking is supported. If the specified value is less than the current length of the stream, the stream is truncated. If the specified value is larger than the current length of the stream, the stream is expanded. If the stream is expanded, the contents of the stream between the old and the new length are not defined.

### Write

<span class="api-meta">override</span>

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

<div class="api-signature" data-lang="csharp">

```csharp
public override void Write(byte[] buffer, int offset, int count)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Sub Write(
    buffer As Byte(),
    offset As Integer,
    count As Integer)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `buffer` | [Byte](https://learn.microsoft.com/dotnet/api/system.byte)[] | An array of bytes. This method copies count bytes from `buffer` to the current stream. |
| `offset` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The zero-based byte offset in `buffer` at which to begin copying bytes to the current stream. |
| `count` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The number of bytes to be written to the current stream. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The sum of `offset` and `count` is larger than the `buffer` length. |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `buffer` is a null reference (Nothing in Visual Basic). |
| [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception) | The `offset` or `count` is negative. |
| [NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception) | The stream does not support writing. |
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The stream has been disposed of. |

**Overrides**

[Write(byte\[\], int, int)](https://learn.microsoft.com/dotnet/api/system.io.stream.write)

**Remarks**

Use the [CanWrite](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/members#canwrite) property to determine whether the current instance supports writing.
