# OpcFileInfo Members

> Reference: Provides properties and instance methods for the opening of files and aids in the creation of OpcFileStream objects.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcFileInfo</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>

## Constructors

### OpcFileInfo

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

| Overload | Description |
|---|---|
| [OpcFileInfo(OpcFileNodeContext)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#opcfileinfo-opc-uafx-client-opcfilenodecontext) | Initializes a new instance of the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) class, which acts as a wrapper for the file node identified by the `context` specified. |
| [OpcFileInfo(OpcClient, OpcNodeId)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#opcfileinfo-opc-uafx-client-opcclient-opc-uafx-opcnodeid) | Initializes a new instance of the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) class, which acts as a wrapper for the file node identified by the `fileNodeId` and accessed using the `client` specified. |

#### OpcFileInfo(OpcFileNodeContext)

Initializes a new instance of the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) class, which acts as a wrapper for the file node identified by the `context` specified.

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

```csharp
public OpcFileInfo(OpcFileNodeContext context)
```

</div>

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

```vbnet
Public Sub New(context As OpcFileNodeContext)
```

</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/) identifying the file node to be wrapped by the new instance. |

**Exceptions**

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

#### OpcFileInfo(OpcClient, OpcNodeId)

Initializes a new instance of the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) class, which acts as a wrapper for the file node identified by the `fileNodeId` and accessed using the `client` specified.

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

```csharp
public OpcFileInfo(OpcClient client, OpcNodeId fileNodeId)
```

</div>

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

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

</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 when accessing the file node information. |
| `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 wrap. |

**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

### CanUserWrite

Gets a value indicating whether the file is writable taking user access rights into account.

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

```csharp
public bool CanUserWrite { get; }
```

</div>

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

```vbnet
Public ReadOnly Property CanUserWrite As Boolean
```

</div>

**Property value**

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

The value true if the current file can be written by the current user; otherwise the value false.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

When first called, [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) calls [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) and caches information about the file. On subsequent calls, you must call [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) to get the latest copy of the information.

This property does not take into account whether the file is currently opened for writing by another client and thus currently locked and not writable by others.

### CanWrite

Gets a value indicating whether the file is writable.

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

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

</div>

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

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

</div>

**Property value**

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

The value true if the current file can be written; otherwise the value false.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

When first called, [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) calls [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) and caches information about the file. On subsequent calls, you must call [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) to get the latest copy of the information.

This property does not take any user access rights into account, i.e. although the file is writable this may be restricted to a certain user / user group. The property does not take into account whether the file is currently opened for writing by another client and thus currently locked and not writable by others.

### Context

Gets the [OpcFileNodeContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilenodecontext/) used to wrap and access the file node its information is to be provided by the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/).

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

```csharp
public OpcFileNodeContext Context { get; }
```

</div>

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

```vbnet
Public ReadOnly Property Context As OpcFileNodeContext
```

</div>

**Property value**

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

An instance of the [OpcFileNodeContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilenodecontext/) class.

### Exists

Gets a value indicating whether the file node represented exists.

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

```csharp
public bool Exists { get; }
```

</div>

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

```vbnet
Public ReadOnly Property Exists As Boolean
```

</div>

**Property value**

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

The value true if the file node exists; otherwise the value false if the file node does not exist.

**Remarks**

When first called, [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) calls [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) and caches information about the file. On subsequent calls, you must call [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) to get the latest copy of the information.

The [Exists](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#exists) property returns false if any error occurs while trying to determine if the specified file node exists. This can occur in situations that raise exceptions.

### Length

Gets the size, in bytes, of the current file represented by the file node described.

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

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

</div>

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

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

</div>

**Property value**

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

The size of the file of the current file node in bytes.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

To get the latest value, call the [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) method.

### MimeType

Gets the media type of the current file represented by the file node described.

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

```csharp
public string MimeType { get; }
```

</div>

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

```vbnet
Public ReadOnly Property MimeType As String
```

</div>

**Property value**

[String](https://learn.microsoft.com/dotnet/api/system.string)

The media type of the file of the current file node based on RFC 2046.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

To get the latest value, call the [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) method.

### Name

Gets the name of the file node described.

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

```csharp
public OpcName Name { get; }
```

</div>

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

```vbnet
Public ReadOnly Property Name As OpcName
```

</div>

**Property value**

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

The [OpcName](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcname/) of the file node described.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

When first called, [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) calls [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) and caches information about the file. On subsequent calls, you must call [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) to get the latest copy of the information.

## Methods

### AppendText

Creates a [StreamWriter](https://learn.microsoft.com/dotnet/api/system.io.streamwriter) that appends text to the file represented by this instance of the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/).

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

```csharp
public StreamWriter AppendText()
```

</div>

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

```vbnet
Public Function AppendText() As StreamWriter
```

</div>

**Returns**

[StreamWriter](https://learn.microsoft.com/dotnet/api/system.io.streamwriter)

A new instance of the [StreamWriter](https://learn.microsoft.com/dotnet/api/system.io.streamwriter) class.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

This method returns a write-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object with the mode set to [AppendWrite](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/#appendwrite).

### Open

Opens a file in the specified `mode`.

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

```csharp
public OpcFileStream Open(OpcFileMode mode)
```

</div>

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

```vbnet
Public Function Open(mode As OpcFileMode) As OpcFileStream
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `mode` | [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) | A [OpcFileMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/) member specifying the mode in which to open the file. |

**Returns**

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

A [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) opened in the specified mode.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

### OpenRead

Creates a read-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/).

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

```csharp
public OpcFileStream OpenRead()
```

</div>

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

```vbnet
Public Function OpenRead() As OpcFileStream
```

</div>

**Returns**

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

A new read-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

This method returns a read-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object with the mode set to [Read](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/#read).

### OpenText

Creates a [StreamReader](https://learn.microsoft.com/dotnet/api/system.io.streamreader) with UTF8 encoding.

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

```csharp
public StreamReader OpenText()
```

</div>

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

```vbnet
Public Function OpenText() As StreamReader
```

</div>

**Returns**

[StreamReader](https://learn.microsoft.com/dotnet/api/system.io.streamreader)

A new [StreamReader](https://learn.microsoft.com/dotnet/api/system.io.streamreader) with UTF8 encoding.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

### OpenWrite

Creates a write-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/).

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

```csharp
public OpcFileStream OpenWrite()
```

</div>

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

```vbnet
Public Function OpenWrite() As OpcFileStream
```

</div>

**Returns**

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

A write-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object.

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The file node described by the current [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object could not be found. |

**Remarks**

This method returns a write-only [OpcFileStream](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfilestream/) object with the mode set to [Write](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/#write).

The stream created does not append the new content to the existing content. Instead, it overwrites the existing data with the new data. If you overwrite longer data (such as "This is a test of the OpenWrite method") with a shorter string (like "Second "), the file will contain a mix of the strings ("Second test of the OpenWrite method").

### Refresh

Refreshes the state and information of the [OpcFileInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/) object.

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

```csharp
public void Refresh()
```

</div>

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

```vbnet
Public Sub Refresh()
```

</div>

**Remarks**

The method takes a snapshot of the file node.

Calls must be made to [Refresh](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcfileinfo/members#refresh) before attempting to get any information, or the information will be outdated.

### ToString

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

Returns the [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) or the [Value](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcname/members#value) of the file node described.

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

```csharp
public override string ToString()
```

</div>

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

```vbnet
Public Overrides Function ToString() As String
```

</div>

**Returns**

[String](https://learn.microsoft.com/dotnet/api/system.string)

A string representing the file node described.

**Overrides**

[ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)
