QuickOPC User's Guide and Reference
GetWritableFileInfo(IEasyUAFileTransfer,UAEndpointDescriptor,UANodeDescriptor,String) Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.FileTransfer Namespace > IEasyUAFileTransferExtension Class > GetWritableFileInfo Method : GetWritableFileInfo(IEasyUAFileTransfer,UAEndpointDescriptor,UANodeDescriptor,String) Method
The OPC UA file transfer object that will perform the operation.
Endpoint descriptor. Identifies the OPC-UA server.
Descriptor of the base node.
Relative path that identifies the file.
Gets a writable file info object for the specified OPC UA file.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function GetWritableFileInfo( _
   ByVal fileTransfer As IEasyUAFileTransfer, _
   ByVal endpointDescriptor As UAEndpointDescriptor, _
   ByVal baseNodeDescriptor As UANodeDescriptor, _
   ByVal subpath As String _
) As IWritableFileInfo
'Usage
 
Dim fileTransfer As IEasyUAFileTransfer
Dim endpointDescriptor As UAEndpointDescriptor
Dim baseNodeDescriptor As UANodeDescriptor
Dim subpath As String
Dim value As IWritableFileInfo
 
value = IEasyUAFileTransferExtension.GetWritableFileInfo(fileTransfer, endpointDescriptor, baseNodeDescriptor, subpath)

Parameters

fileTransfer
The OPC UA file transfer object that will perform the operation.
endpointDescriptor
Endpoint descriptor. Identifies the OPC-UA server.
baseNodeDescriptor
Descriptor of the base node.
subpath
Relative path that identifies the file.

Return Value

Returns a OpcLabs.BaseLib.Extensions.FileProviders.IWritableFileInfo object for the specified OPC UA file.
Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Example

.NET

COM

// Shows how to write data into a section of an OPC UA file, using the file provider model.

using System;
using System.IO;
using System.Text;
using OpcLabs.BaseLib.Extensions.FileProviders;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.FileTransfer;

namespace UADocExamples.FileProviders._WritableFileInfo
{
    class Write
    {
        public static void Main1()
        {
            // Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe)
            UAEndpointDescriptor endpointDescriptor = "opc.tcp://localhost:48030";

            // A node that represents an instance of OPC UA FileType object.
            UANodeDescriptor fileNodeDescriptor = "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile";
            
            // Instantiate the file transfer client object
            var fileTransferClient = new EasyUAFileTransferClient();

            Console.WriteLine("Getting writable file info...");
            IWritableFileInfo writableFileInfo = fileTransferClient.GetWritableFileInfo(endpointDescriptor, fileNodeDescriptor);
            // From this point onwards, the code is independent of the concrete realization of the file provider, and would
            // be identical e.g. for files in the physical file system, if the corresponding file provider was used.

            // Open the file, write a section of it, and close it.
            try
            {
                Console.WriteLine("Opening file...");
                using (Stream stream = writableFileInfo.CreateWriteStream(FileMode.Open, FileAccess.ReadWrite))
                {
                    Console.WriteLine("Writing file section...");
                    byte[] data = Encoding.UTF8.GetBytes("TEXT FROM FILE TRANSFER CLIENT EXAMPLE. Demonstrates writing a section of a file. <<<");
                    stream.Write(data, 0, data.Length);

                    Console.WriteLine("Closing file...");
                    // Disposing of the stream closes the file.
                }
            }
            // Methods in the file provider model throw IOException and other exceptions, but not UAException.
            catch (Exception exception)
            {
                Console.WriteLine($"*** Failure: {exception.GetBaseException().Message}");
                return;
            }

            Console.WriteLine();
            Console.WriteLine("Finished...");
        }
    }
}
# Shows how to write data into a section of an OPC UA file, using the file provider model.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System import *
from System.IO import *
from System.Text import *
from OpcLabs.BaseLib.Extensions.FileProviders import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.FileTransfer import *
from OpcLabs.EasyOpc.UA.Navigation import *


# Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe).
endpointDescriptor = UAEndpointDescriptor('opc.tcp://localhost:48030')

# A node that represents an OPC UA file system (a root directory).
fileNodeDescriptor = UANodeDescriptor('nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile')

# Instantiate the file transfer client object.
fileTransferClient = EasyUAFileTransferClient()

print('Getting writable file info...')
writableFileInfo = IEasyUAFileTransferExtension.GetWritableFileInfo(fileTransferClient,
                                                                    endpointDescriptor,
                                                                    UANamedNodeDescriptor(fileNodeDescriptor))
# From this point onwards, the code is independent of the concrete realization of the file provider, and would
# be identical e.g. for files in the physical file system, if the corresponding file provider was used.

# Open the file, write a section of it, and close it.
stream = None
try:
    print('Opening file...')
    stream = writableFileInfo.CreateWriteStream(FileMode.Open, FileAccess.ReadWrite)

    print('Writing file section...')
    data = Encoding.UTF8.GetBytes('TEXT FROM FILE TRANSFER CLIENT EXAMPLE. Demonstrates writing a section of a file. '
                                  '<<<')
    stream.Write(data, 0, data.Length)

    print('Closing file...')
    # Disposing of the stream (in the 'finally' block) closes the file.

# Methods in the file provider model throw IOException and other exceptions, but not UAException.
except Exception as exception:
    print('*** Failure: ' + exception.GetBaseException().Message)
    exit()

finally:
    stream and stream.Dispose()

print()
print('Finished.')
' Shows how to write data into a section of an OPC UA file, using the file provider model.

Imports System.IO
Imports System.Text
Imports OpcLabs.BaseLib.Extensions.FileProviders
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.FileTransfer

Namespace FileProviders._WritableFileInfo

    Friend Class Write

        Public Shared Sub Main1()

            ' Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe)
            Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://localhost:48030"

            ' A node that represents an instance of OPC UA FileType object.
            Dim fileNodeDescriptor As UANodeDescriptor =
                "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile"

            ' Instantiate the file transfer client object
            Dim fileTransferClient = New EasyUAFileTransferClient

            Console.WriteLine("Getting writable file info...")
            Dim writableFileInfo As IWritableFileInfo =
                fileTransferClient.GetWritableFileInfo(endpointDescriptor, fileNodeDescriptor)
            ' From this point onwards, the code is independent of the concrete realization of the file provider, and would
            ' be identical e.g. for files in the physical file system, if the corresponding file provider was used.

            ' Open the file, write a section of it, and close it.
            Try
                Console.WriteLine("Opening file...")
                Using stream As Stream = writableFileInfo.CreateWriteStream(FileMode.Open, FileAccess.ReadWrite)
                    Console.WriteLine("Writing file section...")
                    Dim data As Byte() = Encoding.UTF8.GetBytes("TEXT FROM FILE TRANSFER CLIENT EXAMPLE. Demonstrates writing a section of a file. <<<")
                    stream.Write(data, 0, data.Length)

                    Console.WriteLine("Closing file...")
                    ' Disposing of the stream closes the file.
                End Using

                ' Methods in the file provider model throw IOException and other exceptions, but not UAException.
            Catch exception As Exception
                Console.WriteLine("*** Failure: {0}", exception.GetBaseException.Message)
                Exit Sub
            End Try

            Console.WriteLine()
            Console.WriteLine("Finished...")
        End Sub
    End Class
End Namespace
Rem This example shows how to write data (a value, timestamps and status code)
Rem into a single attribute of a node.

Public Sub Write_Main_Command_Click()
    OutputText = ""

    Const GoodOrSuccess = 0

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Modify data of a node's attribute
    Dim StatusCode As New UAStatusCode
    StatusCode.Severity = GoodOrSuccess
    Dim AttributeData As New UAAttributeData
    AttributeData.SetValue 12345
    Set AttributeData.StatusCode = StatusCode
    AttributeData.SourceTimestamp = Now()
    
    ' Perform the operation
    On Error Resume Next
    Call Client.Write("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10221", AttributeData)
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0
End Sub
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also