Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
public void DownloadEmailToFolder(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
RDOFolder inbox = this.redemptionSession.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
List<RDOMail> mailItemList = inbox.Items.OfType<RDOMail>().ToList();
foreach (RDOMail mail in mailItemList)
{
string fileName = Path.Combine(path, this.MakeValidFileName(mail.Subject));
try
{
mail.SaveAs(fileName);
}
catch (Exception)
{
throw new InvalidOperationException("Invalid path: " + fileName);
}
}
}
Experts Exchange Solution brought to you by
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
Start your 7-day free trial private string MakeValidFileName(string input)
{
string pattern = "[?:/*]+";
return Regex.Replace(input, pattern, "");
}
public void DownloadEmailToFolder(string path)
{
// Redemption.RDOSession Session = default(Redemption.RDOSession);
dynamic Session = Activator.CreateInstance(Type.GetTypeFromProgID("Redemption.RDOSession"));
Session.Logon();
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
RDOFolder inbox = Session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
List<RDOMail> mailItemList = inbox.Items.OfType<RDOMail>().ToList();
foreach (RDOMail mail in mailItemList)
{
string fileName = Path.Combine(path, this.MakeValidFileName(mail.Subject)+".msg");
//if (mail.ReceivedTime.Equals("03 / 23 / 2012"))
try
{
mail.SaveAs(fileName);
}
catch (Exception)
{
throw new InvalidOperationException("Invalid path: " + fileName);
}
}
}
private string MakeValidFileName(string input)
{
string pattern = "[?:/*]+";
return Regex.Replace(input, pattern, "");
}
private void button1_Click(object sender, EventArgs e)
{
DownloadEmailToFolder("C:\\emails");
}
From novice to tech pro — start learning today.
Experts Exchange Solution brought to you by
What version of Outlook are you using?
Windows Forms or WPF?
What do you mean by "folder" (file or Outlook)?