FtpClient.BeginRename Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Asynchronously renames an object on the server

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

Syntax

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

Parameters

path
Type: System..::..String
The full or relative path to the object
dest
Type: System..::..String
The old or new full or relative path including the new name of the object
callback
Type: System..::..AsyncCallback
Async callback
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

IFtpClient..::..BeginRename(String, String, AsyncCallback, Object)

Examples

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

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

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

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.BeginRename("/source/object", "/new/path/and/name",
                    new AsyncCallback(BeginRenameCallback), conn);

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

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

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

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

See Also