How to get the size of each message file in PST file?


#1

I need to extract each message file within pst file with its size. Is there any field to get the size of the msg file ?


#2

@alishasharma,

I have observed your requirements and suggest you to please try using following options on your end.

using (PersonalStorage personalStorage = PersonalStorage.FromFile(fileName))
{
    FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox");

    foreach (MessageInfo messageInfo in inbox.EnumerateMessages())
    {
        Console.WriteLine("Message size: " + messageInfo.Properties[MapiPropertyTag.PR_MESSAGE_SIZE].GetLong());
    }
}

#3

Thank you!! Can you please tell me how can i retrieve the actual readable data content from the property??


#4

@alishasharma,

I am sorry, I am unable to get your point. The property returns bytes and you may convert it KB or MB as per your application requirements.


#5

Actually, I tried a you said but still I had some error in processing the message file being extracted. But, Now I somehow managed to process the message files. I added the following code and it worked.
using(MemoryStream memorystream = new MemoryStream())
{
msg.Save(memorystream);
byte[] data = memorystream.ToArray();
child.NativeData = data;
}
I saved the msg in memory stream and use it bye array to as message data to process it.


#6

@alishasharma,

It’s good to know things are fine on your end. Please feel free to share if there is any further issue incurring on your end.