Not able to move a message from one folder to another

Hi support,

I am trying this article with exchange server but I am having problem with moving the message from inbox to another folder. Can you please provide some working code sample for this?

Thank you

Hi Cornelius,

Thank you for writing to us.

Please have a look at the following code sample for your kind reference. In order to move the queries from source to destination folder, the code first checks if the destination folder exists. If yes, then it moves the fetched messages to the destination folder. Please try it at your end and let us know your feedback.

Sample Code:

// Create instance of ExchangeWebServiceClient class by giving credentials
ExchangeWebServiceClient client = new ExchangeWebServiceClient("https://exchange.domain.com/ews/Exchange.asmx", "user.test@domain.com", "l@!qwQew");

// Check if the destination folder exists..subfolderInfo will not be NULL if it exists
ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo();
client.FolderExists(client.MailboxInfo.RootUri, "Archive", out subfolderInfo);

if (subfolderInfo == null)
    return;

// Call ListMessages method to list messages info from Inbox
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri, 2);

// Loop through the collection to display the basic information
foreach (ExchangeMessageInfo msgInfo in msgCollection)
{
    Console.WriteLine("Subject: " + msgInfo.Subject);
    Console.WriteLine("From: " + msgInfo.From.ToString());
    Console.WriteLine("To: " + msgInfo.To.ToString());

    string strMessageURI = msgInfo.UniqueUri;

    // Now get the message details using FetchMessage()
    MailMessage msg = client.FetchMessage(strMessageURI);

    // Display message details
    Console.WriteLine("Subject: " + msg.Subject);
    //Console.WriteLine("HTML Body: " + msg.HtmlBody);

    // How many attachments
    Console.WriteLine("Number of attachments: " + msg.Attachments.Count);

    // List the attachments
    foreach (Attachment att in msg.Attachments)
    {
        Console.WriteLine("Attachment Name: " + att.Name);
    }

    client.MoveItem(msgInfo.UniqueUri, subfolderInfo.Uri);
}