Delete PST Item

Platform : NET 3.5
Outlook : 2007
Aspose Email Trial

I have a problem when I try to delete an item of PST.

Code:

FolderInfo folderInfo = pst.GetPredefinedFolder(StandardIpmFolder.DeletedItems);
Console.WriteLine("Delete messages: " + folderInfo.ContentCount);
MessageInfoCollection msgInfoColl = folderInfo.GetContents();
int i = 0;

foreach (MessageInfo msgInfo in msgInfoColl)
{
i++;
Console.WriteLine(msgInfo.Subject + ": " + msgInfo.EntryIdString);
// delete this item
folderInfo.DeleteChildItem(msgInfo.EntryId);
Console.WriteLine("Deleted this message");
}
Console.WriteLine(i + "deleted items");

After executing this code, when I open pst file and I select "Deleted Items" folder I get this message:

"Cannot open the folder. Has been detected errors in .pst file".

The rest of folders works correctly.

Thanks.

Hi,


Thank you for contacting support.

We have tried on our end to reproduce the said issue by using Aspose.Email for .NET v1.9.0 and a sample file of our own. I am afraid the problem didn’t replicate. We would request you to please give the latest assemblies a try and feed us back with your results.

In case your problem persists, we would like to review your sample PST, as the problem seems to be sample specific.

Best Regards,

Ok, with v.1.9.0 it works. How can I update “Unread items” value? When I delete all items of “Delete items”, still indicates the same value. This must be zero.


Thanks in advance.

Hi,


Regarding the number of messages in “Deleted Items”, is it possible for you to provide your sample PST as well as code snippet for our review?

If you wish to update the “Unread Items” value for some folder in PST then I am afraid such feature is not supported yet. I will look into it to suggest any workaround for your situation.

Regards,

Here you have the code and pst file after removing (with four unread items). I have tried with more pst and all give me the same problem.


In addition,I get errors when I try to delete, for example, 2 items in a folder that contains 20. I mean, delete a part of folder produces errors in pst file.

Thanks!
Hi,

Thank you for providing us the sample code and PST.

I am able to observe the problem of unread messages in the Delete Items of the given PST, even though there are no messages after deletion. I have logged a ticket in our bug tracking system to probe further into this matter and we will keep you posted with updates. The ticket Id for your reference is NETWORKNET-33341.

Javi OD:
In addition,I get errors when I try to delete, for example, 2 items in a folder that contains 20. I mean, delete a part of folder produces errors in pst file.

Could you please elaborate the above said problem with the help of code snippet or snapshot, if required?

Thanks and Regards,

Of course. At first, “Deleted items” have +600 items.

FolderInfo folderInfo = pst.GetPredefinedFolder(StandardIpmFolder.DeletedItems);

MessageInfoCollection msgInfoColl = folderInfo.GetContents();

//Delete all items

[//folderInfo.getContent](https://folderinfo.getcontent/), delete 50 items

foreach (MessageInfo msgInfo in msgInfoColl)

{

Console.WriteLine(msgInfo.Subject);

// delete this item

folderInfo.DeleteChildItem(msgInfo.EntryId);

Console.WriteLine(“Deleted this message”);

}

Best regards!

Hi Javier,


Thank you for sharing the snapshot and the sample code.

I am trying to understand the problem cause, but I am afraid I am unable to understand the error message in Outlook application from your shared image. It will greatly help us if you can copy paste the text from outlook to your post so I may translate it using any translator available.

Moreover, I believe the problem arise when you delete all messages from a PST folder and then load the same in Outlook to view it’s contents. If I am correct in my understanding then please also share the Outlook application version so I could setup the same version on my end and try to replicate the issue to raise a ticket for it.

Just for your knowledge, I have tried a similar procedure on a sample PST and loaded it in Outlook 2010 32 bit. On my end, no error was displayed in the viewing pane.

Regards,

Hi! This is the outlook message (spanish):


" No se puede mostrar la carpeta. Se han detectado errores en el archivo C:/… . Salga de outlook y de todas las aplicaciones de correo y , a continuación, utilice la herramienta Reparar Bandeja de entrada (scanpst.exe) para diagnosticar y reparar los errores del archivo. Para obtener mas información sobre esta herramienta vea la ayuda."

Outlook: 2007
Microsoft Windows Vista 32 bits

1º Delete all messages works well but ocurrs the “Unread messages problem”.

2º Delete part of folder: Occurs the “Unread messages” problem and I get the message when I open the folder.

Thanks!

Edit:

In Windows 7 32 bits and Outlook 2010 I get the same problem. Moreover folderinfo.getContents() only return 50 items. Could you send me the code in .NET with which you are performing the test in w7 & outlook 2010?

Another thing, it would be interesting be able to compact a pst file after removing for decrease its weight











Hi,


Thank you for sharing more information.

The message says that the PST has got corrupted and its contents can not be retrieved. I have been trying my end to reproduce this error but so far I haven’t succeeded with Windows 7 64bit and Outlook 2010 14.0.6112.5000 32bit.

Below is my sample code to delete all the messages from Deleted Items folder.


using (var pst = PersonalStorage.FromFile(“archive-Deleted.pst”))
{
var root = pst.RootFolder;
var deleted = root.GetSubFolder(“Deleted Items”);
var collection = deleted.GetContents();
foreach (var messageInfo in collection)
{
deleted.DeleteChildItem(messageInfo.EntryId);
}

}

I have noticed that if I interrupt the deletion process in middle (by stopping the program after some messages got delete), it corrupts the PST and Outlook cannot open it to view the folder contents.

Moreover, I would like to inform you that current implementation of Aspose.Email does not support compaction of PST. You may also notice that there is no change in PST file size even after deleting all messages from all sub-folders. This is a known behavior and if you like I can log an enhancement for PST compaction.

Regards,

Thanks for your answers.


In a windows 7 with outlook 2010 14.0.6112.5000 (64 bits) I get the same error again. Your code delete all messages? In my case, using your code, delete 50 items and stop. Any suggestion? I though of recording a video for show you this problem.

Regards!


Hi,


Thanks for writing back.

We believe you are using Aspose.Email in Evaluation mode. This is the limitation of Evaluation mode to delete only 50 messages from a given PST. If you are evaluating the product then I would suggest you to get a 30 days temporary license by following the instructions given on below linked page.
http://www.aspose.com/corporate/purchase/temporary-license.aspx

Please also check the related technical article on how to set the license.

Regards,

ok. I have another question. With this component, can I? :


- save emails in xml, eml, html
- save attachments for every item
- search in any folder of pst

Notice me when the “unread items” problem has been fixed.

Thanks in advance.

Hi,


Thank you for your inquiry. Please find below the answers,

  • Using just Aspose.Email for .NET component, you can convert any message to EML. In order to convert the email message to Html, you have to use Aspose.Words in collaboration with Aspose.Email component. MailMessage class from Aspose.Email will first convert the message to Mhtml. Document class from Aspose.Words will load the Mhtml and can convert it to Html format. For conversion to Xml, you may need to post an inquiry on Aspose.Words forum.
  • You can extract all kinds of attachments from a given message.
  • Currently there are no direct means available to search an item from any given folder of a Personal Storage file (PST). If you could elaborate your scenario further, I will check back with the development team and add a new feature request to bring the feature on our road map of Aspose.Email.

Regarding the “Unread Messages” problem logged earlier as NETWORKNET-33341, we have an automatic notification system that will notify you once the issue is resolved.

Regards,

Thank you very much. Could you provide me an example of save pst item to eml? I’ve tried to search in web page but I can’t find it.


I need to do something like this but with .eml:

message.Save(@“C:\Users\Javier\Desktop\Pruebas” + message.Subject + “.msg”);


Best regards!

Hi,


Please note that an extracted message from a PST is always an object of MapiMessage class. In order to convert this message to EML format, you need to save the MapiMessage, load it back with MailMessage and then save it in EML format. Below is the code snippet for your reference.

C#

int i = 0;
//Load a pst
var pst = Aspose.Email.Outlook.Pst.PersonalStorage.FromFile(@“Outlook.pst”);
//Inbox folder
var folderInfo = pst.RootFolder.GetSubFolder(“Inbox”);
//Get all contents of Inbox
var messageInfoCollection = folderInfo.GetContents();
//Loop over the items of Inbox
foreach (var messageInfo in messageInfoCollection)
{
//Extract one message
MapiMessage mapiMessage = pst.ExtractMessage(messageInfo);
using (var stream = new System.IO.MemoryStream())
{
//Save extracted message to MemoryStream
mapiMessage.Save(stream);
//Load the message into an instance of MailMessage
MailMessage mailMessage = MailMessage.Load(stream, MessageFormat.Msg);
//Save the message to EML format
mailMessage.Save(++i + “.eml”, MailMessageSaveType.EmlFormat);
}
}

Thank you babar! During the testing I have an exception when I try to create a PersonalStorage instance with the same path. Example:


PersonalStorage file = PersonalStorage.FromFile(path,true);
PersonalStorage file2 = PersonalStorage.FromFile(path, true);

It says that file are in use. I mean, I only can open a pst file one time. Is correct?

Thanks!


Hi,


You are right, you can load the PST (with same name and file path) in only one instance of PersonalStorage unless the prior instance was destroyed. This is the default behavior of Aspose.Email component.

Regards,

Hi again and thanks for all your replies. I have been testing about a week and I get a problem with pst attachments. If attachments has .eml extension I can’t get name and extension of this attachment. I get name = “” and extension = “” in the attachment properties . In other files like .pdf works well.



Thanks in advance!


Hi,


Sorry for the delayed response.

I have tried your scenario at my end, unfortunately I am unable to reproduce the recently posted issue on my end while using Aspose.Email for .NET v1.9.0. I have a sample PST that has one message in its Inbox. The message in turn contains an EML as attachment. When I extracted the message from PST, I can read the attachment name and it’s extension just fine. Below is the sample code for you reference,

C#

var pst = PersonalStorage.FromFile(“E:\sample.pst”);
var contents = pst.RootFolder.GetSubFolder(“Inbox”).GetContents();
foreach (var messageInfo in contents)
{
var message = pst.ExtractMessage(messageInfo);
if (message.Attachments.Count > 0)
{
Console.WriteLine(message.Attachments[0].DisplayName.ToString());
Console.WriteLine(message.Attachments[0].Extension);
}
}

Please provide us your sample so I can reproduce the problem and raise a ticket for it.

Thank you for your understanding and consideration.
Regards,