FtpClient.BeginDeleteDirectory Method (String, Boolean, FtpListOption, AsyncCallback, Object)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Asynchronously removes a directory from the server

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public IAsyncResult BeginDeleteDirectory(
	string path,
	bool force,
	FtpListOption options,
	AsyncCallback callback,
	Object state
)
Visual Basic
Public Function BeginDeleteDirectory ( 
	path As String,
	force As Boolean,
	options As FtpListOption,
	callback As AsyncCallback,
	state As Object
) As IAsyncResult
Visual C++
public:
virtual IAsyncResult^ BeginDeleteDirectory(
	String^ path, 
	bool force, 
	FtpListOption options, 
	AsyncCallback^ callback, 
	Object^ state
) sealed

Parameters

path
Type: System..::..String
The full or relative path of the directory to delete
force
Type: System..::..Boolean
If the directory is not empty, remove its contents
options
Type: System.Net.FtpClient..::..FtpListOption
FtpListOptions for controlling how the directory contents are retrieved with the force option is true. If you experience problems the file listing can be fine tuned through this parameter.
callback
Type: System..::..AsyncCallback
Async callback
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

IFtpClient..::..BeginDeleteDirectory(String, Boolean, FtpListOption, AsyncCallback, Object)

Examples

C#  Copy imageCopy
using System;
using System.Net;
using System.Net.FtpClient;
using System.Threading;

namespace Examples {
    class BeginDeleteDirectoryExample {
        static ManualResetEvent m_reset = new ManualResetEvent(false);

        public static void BeginDeleteDirectory() {
            using (FtpClient conn = new FtpClient()) {
                m_reset.Reset();

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.CreateDirectory("/some/test/directory");
                conn.BeginDeleteDirectory("/some", true, new AsyncCallback(DeleteDirectoryCallback), conn);

                m_reset.WaitOne();
                conn.Disconnect();
            }
        }

        static void DeleteDirectoryCallback(IAsyncResult ar) {
            FtpClient conn = ar.AsyncState as FtpClient;

            try {
                if (conn == null)
                    throw new InvalidOperationException("The FtpControlConnection object is null!");

                conn.EndDeleteDirectory(ar);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                m_reset.Set();
            }
        }
    }
}

See Also