问题
I'm writing a program in C# using Redemption to iterate through the RDOMail objects in a RDOPstStore and copy the ones marked as relevant to a new RDOPstStore. I can modify the folders in the RDOPstStore.IPMRootFolder, and do so to only leave one folder (Results). However when I go to add RDOMail items to this folder (saved in a list previously) the items do not appear in the folders Items member. Is there something I am missing in order to ensure the "added" RDOMail object is saved in the RDOPstStore object? Here is the code
//create an output session
RDOSession outputSession = new RDOSession(@"Redemption.RDOSession");
//logon/create output store
outputStore = outputSession.LogonPstStore(outputDir + '\\' + filename);
//clear the output store of any folders, we will leave only one: Results
foreach (RDOFolder folder in outputStore.IPMRootFolder.Folders)
{
folder.Delete(); //successful
}
RDOFolder resultsFolder = outputStore.IPMRootFolder.Folders.Add("Results");
foreach(RDOMail mail in relevantItems) //relevantItems gathered previously
{
resultsFolder.Items.Add(mail); //unsuccessful
resultsFolder.Save();
}
/******************EDIT 5/26****************/
outputStore.Save();
outputSession.Logoff();
/******************END EDIT*****************/
All help much appreciated!
回答1:
Firstly, LogonPstStore returns an instance of the RDOPstStore object - there is no reason to retrieve it from the Stores collection or add it a second time.
outputStore = outputSession.LogonPstStore(outputDir + '\\' + filename);
Secondly, PST provider commits the changes to the PST file at a later point or when the session is closed. Does your app terminate gracefully? Do you call RDOSession.Logoff?
回答2:
Wait a second, you were not saving the message that you added - you called save on the folder instead of the item returned by Items.Add:
RDOMail item = resultsFolder.Items.Add(mail);
item.Save();
回答3:
OK so I was able to discover the issue. @Dmitry Streblechenko was right that I did not need to add a new PST Store after logging onto the Pst Store (which creates a new file if necessary).
BUT the true issue was in copying files to the newly created PST Store. The problem was using the RDOFolder.Items.Add(RDOMail)
function. As intuitive as this Add()
function may be the correct (or at the very least effective) approach is to use the RDOMail.CopyTo(RDOMail/RDOFolder)
function. As so...
mail.CopyTo(resultsFolder);
This successfully placed the RDOMail object into the RDOFolder object, whereas the Add() function wouldn't. As a side note I read up another post @Dmitry helped on and he mentions that the Add()
function is used to create new items, so it may not be completely useless. Although it seems that one could create a new RDOMail object, modify it, then use it's CopyTo()
function...
Lesson learned.
来源:https://stackoverflow.com/questions/30407435/redemption-cannot-add-item-to-folder