# OpcFileOpenMethodNode.FileOpenExCallback Delegate

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

Opens the file represented. When a client opens a file it gets a file handle that is valid while the session is open. Clients shall use the Close Method to release the file handle when they do not need access to the file anymore. Clients can open the same file several times for read.

## Syntax

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

```csharp
public delegate uint OpcFileOpenMethodNode.FileOpenExCallback(
    OpcMethodContext context,
    byte mode)
```

</div>

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

```vbnet
<CLSCompliant(False)>
Public Delegate Function OpcFileOpenMethodNode.FileOpenExCallback(
    context As OpcMethodContext,
    mode As Byte) As UInteger
```

</div>

## Parameters

| Name | Type | Description |
|---|---|---|
| `context` | [OpcMethodContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmethodcontext/) | The [OpcMethodContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmethodcontext/) to use when opening the file. This instance will be also updated with the outcome of the method call. |
| `mode` | [Byte](https://learn.microsoft.com/dotnet/api/system.byte) | Indicates whether the file should be opened only for read operations or for read and write operations and where the initial position is set. |

## Returns

[UInt32](https://learn.microsoft.com/dotnet/api/system.uint32)

A handle for the file used in other method calls indicating not the file but the access request and thus the position in the file. The file handle is generated by the server and is unique for the Session. Clients cannot transfer the file handle to another Session but need to get a new file handle by calling the Open Method.

## Remarks

This method does provide the following [OpcResult](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcresult/) information:

- [BadNotReadable](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnotreadable)The file might be locked and thus not readable. This is also the case there the file is already opened for writing by the current or a different session.
- [BadNotWritable](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnotwritable)The `mode` refers to [Write](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcfilemode/#write) but neither 'CanWrite' nor 'CanUserWrite' grant write access. This is also the case there the file is already opened by the current or a different session.
- [BadInvalidState](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidstate)The file is locked and thus not writable.
- [BadInvalidArgument](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidargument)The `mode` configuration is invalid.
- [BadNotFound](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnotfound)The file maintained by the file node does not exist.
- [BadUnexpectedError](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badunexpectederror)An unexpected error occurred while opening the file.

## Applies to

| Package | Versions |
|---|---|
| Opc.UaFx.Advanced | v2.5–v2.59 |
