Handling multiple attachment

Hi,
If I have multiple attachment how can i add into pst file.Please reply soon.

Hi Pooja,

You can not add attachments directly to the PST. You first need to add these to MailMessage or MapiMessage and then add that message to the PST. Please have a look at our article for further clarification and the following code for your kind reference.

Sample Code:

PersonalStorage pst = PersonalStorage.Create(“Attachments.pst”, FileFormatVersion.Unicode);

FolderInfo folderInfo = pst.RootFolder.AddSubFolder("Test");

MailMessage mailMsg = new MailMessage();

mailMsg.Attachments.Add(new Attachment("someAttachment.txt"));

MapiMessage mapiMsg = MapiMessage.FromMailMessage(mailMsg);

folderInfo.AddMessage(mapiMsg);