QuickOPC User's Guide and Reference
Examples - OPC UA File Providers - Get file properties
View with Navigation Tools

The example below shows how to get OPC UA file properties (such as its size or last modified time), using the file provider model.

// Shows how to get OPC UA file properties (such as its size or last modified time), using the file provider model.

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

namespace UADocExamples.FileProviders._FileInfo2
{
    class Properties
    {
        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 file info...");
            IFileInfo2 fileInfo2 = fileTransferClient.GetFileInfo2(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.

            // Get properties of a specified file.
            Console.WriteLine("Getting file properties...");
            try
            {
                // Display result
                Console.WriteLine();
                Console.WriteLine($"Exists: {fileInfo2.Exists}");
                Console.WriteLine($"IsDirectory: {fileInfo2.IsDirectory}");
                Console.WriteLine($"LastModified: {fileInfo2.LastModified}");
                Console.WriteLine($"Length: {fileInfo2.Length}");
                Console.WriteLine($"Name: {fileInfo2.Name}");
                Console.WriteLine($"PhysicalPath: {fileInfo2.PhysicalPath}");
            }
            // 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...");
        }
    }
}

 

See Also

Examples - OPC UA File Transfer

Conceptual