MoveItem not working with newly created folder. Exchange 2007 C# .NET

I’m struggling with moving email to newly created folder. (I’m using Exchange 2007) Please advise.


I was using this url as guidance:

Working with Folders on IMAP Server|Documentation


I created folder on the root called “Testing”

Here is my code snippet:

NetworkCredential credentials = new NetworkCredential(Properties.Settings.Default.Exchange_Username, Properties.Settings.Default.Exchange_Password);

EWSClient client = EWSClient.GetEWSClient(Properties.Settings.Default.Exchange_EWS_Url,
credentials)

ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.Subject.Equals(“Test”);
builder.InternalDate.BeforeOrEqual(DateTime.Now);

MailQuery query = builder.GetQuery();

ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri, query);

foreach (ExchangeMessageInfo msgInfo in msgCollection)
{
client.MoveItem(msgInfo.UniqueUri, client.MailboxInfo.RootUri + “/Testing/” + msgInfo.Subject);
}

I get this error:
Item move failed. System.InvaidOperationException: Item move failed.

I even tried this:
client.MoveItem(msgInfo.UniqueUri, client.MailboxInfo.RootUri + “/Testing/”)

However I was able to successfully move to a predefined folder:
client.MoveItem(msgInfo.UniqueUri, client.MailboxInfo.DeletedItemsUri);

Hi Jason,

Thank you for contacting Aspose support team.

I have tested the code and seems that you are not providing destination uri properly. You may use FolderExists() function to get the uri of the target folder for moving messages. Could you please give a try to the following sample code and provide feedback?

IEWSClient client = GetAsposeClient();
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo();
client.FolderExists(mailboxInfo.RootUri, "Testing", out subfolderInfo);

// List all messages from Inbox folder
Console.WriteLine("Listing all messages from Inbox....");
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);

foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
{
    client.MoveItem(msgInfo.UniqueUri, subfolderInfo.Uri);
    Console.WriteLine("Message moved...." + msgInfo.Subject);
}

I just tested it and it finally works :slight_smile: Thank you!!!

Hi Jason,


Thank you for providing feedback. Please feel free to write us back for any other query related to Aspose.Email.