OPC Studio User's Guide and Reference
DeleteDirectory(IEasyUAFileTransfer,UAEndpointDescriptor,UANodeDescriptor,String) Method
Example 



View with Navigation Tools
OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.FileTransfer Namespace > IEasyUAFileTransferExtension Class > DeleteDirectory Method : DeleteDirectory(IEasyUAFileTransfer,UAEndpointDescriptor,UANodeDescriptor,String) Method
The OPC UA file transfer object that will perform the operation.
Endpoint descriptor. Identifies the OPC-UA server.
Node descriptor of the OPC UA directory.
A name of the OPC UA directory to delete.
Deletes an existing OPC UA directory.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Sub DeleteDirectory( _
   ByVal fileTransfer As IEasyUAFileTransfer, _
   ByVal endpointDescriptor As UAEndpointDescriptor, _
   ByVal directoryNodeDescriptor As UANodeDescriptor, _
   ByVal existingDirectoryName As String _
) 
 
'Usage
 
Dim fileTransfer As IEasyUAFileTransfer
Dim endpointDescriptor As UAEndpointDescriptor
Dim directoryNodeDescriptor As UANodeDescriptor
Dim existingDirectoryName As String
 
IEasyUAFileTransferExtension.DeleteDirectory(fileTransfer, endpointDescriptor, directoryNodeDescriptor, existingDirectoryName)

Parameters

fileTransfer
The OPC UA file transfer object that will perform the operation.
endpointDescriptor
Endpoint descriptor. Identifies the OPC-UA server.
directoryNodeDescriptor
Node descriptor of the OPC UA directory.
existingDirectoryName
A name of the OPC UA directory to delete.
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.

The OPC UA operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks

The directoryNodeDescriptor must be an existing node in the server, of object type OpcLabs.EasyOpc.UA.AddressSpace.Standard.UAObjectTypeIds.FileDirectoryType.

The directoryNodeDescriptor is a parent directory of the directory to be deleted.

This method throws a OpcLabs.EasyOpc.UA.OperationModel.UAException exception if the directory does not exist.

Recommendation: Whenever possible, do not use this method directly, and use a higher-level abstraction instead. See e.g. the GetWritableDirectoryContents(IEasyUAFileTransfer,UAEndpointDescriptor,UANamedNodePath) method, which allows you to obtain an object that can be used to manage directories, in a way that is generic and not tied to OPC UA specifics.

Example

.NET

// Shows how to create and delete OPC UA directories, using the file transfer client.
// Note: Consider using a higher-level abstraction, OPC UA file provider, instead.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.Extensions;
using OpcLabs.EasyOpc.UA.FileTransfer;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples.FileTransfer._EasyUAFileTransferClient
{
    class CreateDirectoryAndDelete
    {
        public static void Main1()
        {
            // Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe)
            var endpointDescriptor = new UAEndpointDescriptor("opc.tcp://localhost:48030")
                .WithUserNameIdentity("john", "master");

            // An object that aggregates an OPC UA file system.
            UANodeDescriptor objectDescriptor = "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files";

            // Create a random number generator - will be used for file/directory names.
            var random = new Random();
            
            // Instantiate the file transfer client object
            var fileTransferClient = new EasyUAFileTransferClient();

            // Create two directories, and one nested directory, and delete the first one.
            try
            {
                // The file system node is a root directory of the file system.
                Console.WriteLine("Getting file system...");
                UANodeDescriptor fileSystemNodeDescriptor = fileTransferClient.GetFileSystem(endpointDescriptor, objectDescriptor);

                string directoryName1 = "MyDirectory1-" + random.Next();
                Console.WriteLine($"Creating first directory, '{directoryName1}'...");
                UANodeId directoryNodeId1 = fileTransferClient.CreateDirectory(endpointDescriptor, fileSystemNodeDescriptor, directoryName1);
                Console.WriteLine($"Node Id of the first directory: {directoryNodeId1}");

                string directoryName2 = "MyDirectory2-" + random.Next();
                Console.WriteLine($"Creating second directory, '{directoryName2}'...");
                UANodeId directoryNodeId2 = fileTransferClient.CreateDirectory(endpointDescriptor, fileSystemNodeDescriptor, directoryName2);
                Console.WriteLine($"Node Id of the second directory: {directoryNodeId2}");

                string nestedDirectoryName = "MyDirectory3-" + random.Next();
                Console.WriteLine($"Creating nested directory, '{nestedDirectoryName}'...");
                // Note how directoryNodeId2 (a parent directory) is passed as the 2nd argument to the CreateDirectory method.
                UANodeId nestedDirectoryNodeId = fileTransferClient.CreateDirectory(endpointDescriptor, directoryNodeId2, nestedDirectoryName);
                Console.WriteLine($"Node Id of the nested directory: {nestedDirectoryNodeId}");

                // At this moment, the directory structure we have created looks like this:
                // * MyDirectory1
                // * MyDirectory2
                // * * MyDirectory3

                Console.WriteLine("Deleting the first directory...");
                fileTransferClient.DeleteDirectory(endpointDescriptor, fileSystemNodeDescriptor, directoryName1);
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
                return;
            }

            Console.WriteLine("Finished...");
        }
    }
}
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