Set specific folder to extract pst to

I'm following the example code here

http://www.aspose.com/documentation/.net-components/aspose.email-for-.net/extract-messages-from-outlook-pst-file-and-save-to-disk-or-stream-in-msg-format.html

The pst's are extracted to the directory where my executable is run. Is there a way to specify this directory instead?

Also when extracted I get an error about an illegal filename. Is there a way to strip off the illegal characters in the msg files?

Thanks

Hi,


Thank you for inquiry.

You can specify the directory in the first parameter of Save() method.

// save this message to disk in msg format

message.Save(“d:\somedir\” + folderInfo.DisplayName + message.Subject.Replace(":", " “) + “.msg”);


In this example, we are saving the message as {Subject}.msg. The subject may contain characters like :, <, > etc which are not permitted as file names. You may write a utility method to strip off such characters.

private static string GetRidOfIllegalFileNameCharacters(string strName)
{
string strLegalName = strName.Replace(”:", " “).Replace(”\", " “).Replace(”?", " “).Replace(”/", " “).Replace(”|", " “).Replace(”*", " “).Replace(”<", " “).Replace(”>", " “).Replace(’\u0009’.ToString(), " “).Replace(””", " “).Replace(“”, " “);
strLegalName = Regex.Replace(strLegalName, @”[^\u0000-\u007F]”, “”);
if (strLegalName.Length >= 100)
{
strLegalName = strLegalName.Substring(0, 100);
}
return strLegalName;
}

Call this method when you save as MSG.

// save this message to disk in msg format

message.Save(“d:\somedir\” + folderInfo.DisplayName + GetRidOfIllegalFileNameCharacters(message.Subject);