FtpClient.BeginCreateDirectory Method (String, Boolean, AsyncCallback, Object)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Creates a directory asynchronously

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

Syntax

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

Parameters

path
Type: System..::..String
The full or relative path to the directory to create
force
Type: System..::..Boolean
Try to create the whole path if the preceding directories do not exist
callback
Type: System..::..AsyncCallback
Async callback
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

IFtpClient..::..BeginCreateDirectory(String, Boolean, AsyncCallback, Object)

Examples

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

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

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

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.DeleteDirectory("/test", true);
                conn.BeginCreateDirectory("/test/path/that/should/be/created", true,
                    new AsyncCallback(CreateDirectoryCallback), conn);

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

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

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

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

See Also