We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PST won't open after adding MSG files

I created a PST file using the ASPOSE EMail API and then add MSG files using the same API but when I try to open the file in Outlook, I get an errorERROR:Cannot expand the folder. Windows Search exitied without properly closing your Outlook data file. I've attached a screen shot of the error.Here is some of the code I'm using.

Aspose.Email.Outlook.Pst.PersonalStorage pst = Aspose.Email.Outlook.Pst.PersonalStorage.FromFile(@"c:\temp\temp.pst" );
Aspose.Email.Outlook.Pst.FolderInfo fi = pst.RootFolder;

foreach (var folder in folders)
{

FolderInfo lookup= fi.GetSubFolder(folder);

if (lookup == null)
{

fi = fi.AddSubFolder(folder);

}
else
{
fi = lookup;
}

fi.AddMessage(Aspose.Email.Outlook.MapiMessage.FromFile(exportItem.ExportFilePath)); Aspose.Email.Outlook.Pst.PersonalStorage pst = Aspose.Email.Outlook.Pst.PersonalStorage.FromFile(@"c:\temp\temp.pst" );
Aspose.Email.Outlook.Pst.FolderInfo fi = pst.RootFolder;

foreach (var folder in folders)
{

FolderInfo lookup= fi.GetSubFolder(folder);

if (lookup == null)
{

fi = fi.AddSubFolder(folder);

}
else
{
fi = lookup;
}

fi.AddMessage(Aspose.Email.Outlook.MapiMessage.FromFile(exportItem.ExportFilePath));

Hi Cheryl,


Thank you for using Aspose.Email.

From your code sample, its not clear if you want to add messages to some specific folder on a PST or to all folders. Below is the sample code that I have used to:

  1. Create a new PST
  2. Add a subfolder to the Root of the PST
  3. Get the reference to the created subFolder
  4. Add a message to the subfolder
and it works fine for me. Please try it at your end and let us know your feedback. You may also consider referring to our online documentation samples that include detailed examples of working with PST files. Please feel free to write to us if you still face any issues while working with Aspose.Email. We’ll be glad to assist you further.

Sample Code:

PersonalStorage pst = PersonalStorage.Create(“NewPst1.pst”, FileFormatVersion.Unicode);<o:p></o:p>

pst.RootFolder.AddSubFolder("Test Folder");

//get the added subfodler

FolderInfo fi = pst.RootFolder.GetSubFolder("Test Folder");

//and add a message to it

fi.AddMessage(MapiMessage.FromFile("E00002728.msg"));