我有一些代碼將項目從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抱歉被意外複製了。我現在已經修改過了。 –