我有一些代码将项目从Deleted Items移动到邮件文件夹中。该代码运行良好,并通常移动所有项目。当它遇到不是IPM的项目时会发生此问题。它给出了一个空引用的错误(请参阅:What is a NullReferenceException, and how do I fix it?)EWS FindItemsResults <Item> Item.Move()不会将某些项目类型移动到Mail文件夹,如IPM.Appointment
这是奇怪的,因为那里有项目,它不能为空。
下面是一个代码摘录:
// Specify the Exchange Service
ExchangeService E_SERVICE = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
// Look at the root of the Mailbox (Top of Information Store)
FolderId fldr_id = WellKnownFolderName.MsgFolderRoot;
// Define the folder view
FolderView newFV = new FolderView(1000);
// Perform a deep traversal
newFV.Traversal = FolderTraversal.Deep;
// Get the results of all the folders in the Mailbox
FindFoldersResults f_results = E_SERVICE.FindFolders(fldr_id, newFV);
// Define the source and target folder id variables as null.
FolderId src_fldr_id = null;
FolderId tgt_fldr_id = null;
// Define the folders we are looking to move items from the source to the target
string source = "Deleted Items"
string target = "Old Deleted Items"
// Search through all the folders found in the mailbox
foreach (Folder fldr in f_results)
{
// If the source folder name is the same as the current folder name then set the source folder ID
if (fldr.DisplayName.ToLower() == source.ToLower())
{
src_fldr_id = fldr.Id;
}
// If the target folder name is the same as the current folder name then set the target folder ID
if (fldr.DisplayName.ToLower() == target.ToLower())
{
tgt_fldr_id = fldr.Id;
}
}
// Get all the items in the folder
FindItemsResults<Item> findResults = E_SERVICE.FindItems(src_fldr_id, new ItemView(1000));
// If the number of results does not equal 0
if (findResults.TotalCount != 0)
{
// For each item in the folder move it to the target folder located earlier by ID.
foreach(Item f_it in findResults)
{
f_it.Move(tgt_fldr_id);
}
}
我们得到扔在以下行错误:
f_it.Move(tgt_fldr_id);
这是一个空引用异常,可并非如此,因为是那里的项目,它通常是一个不是IPM.Note的项目。
那么我该如何解决这个问题,并确保物品被移动,而不管它是什么类型?
我以前在这里发布了关于这个Unable to move Mail items of different Item classes from the same folder using EWS
只有被击落它是一个NullReferenceException时,这是不是这样的!
所以任何有用的答案将不胜感激。
'文件夹src_folder = Folder.Bind(E_SERVICE,src_fldr_id);'你做这个绑定,但没有在其他地方使用它? –
@CallumLinington抱歉被意外复制了。我现在已经修改过了。 –