I’m working in .NET 3.5, Visual Studio 2010. I’m working on an Outlook Add-In that saves some email into a folder. I’ve gotten it to work using the Microsoft.Office.Interop.Outlook.MailItem.SaveAs function. However, the file properties have only the current time (time when the file was exported through the Add-In) as their Date Modified/Date Created etc., and other properties such as To, From, CC, BCC are not there.
If you open a folder in Windows Explorer (I’m using Windows 7), go to the top where it says Name, Date Modified, Type, etc., you can click on More, and see other various columns that might be relevant like “Album Artist”, “To”, “From”, etc.
C# has a really easy way to modify the timings, File.SetCreationTime(filename, DateTime object);. However, there’s no .SetTo or .SetAlbumArtist or anything like that. How would I go about modifying those properties?
Update 1: through research, I found this link: Read/Write 'Extended' file properties (C#), so that might contain the answer…but I have no idea how. The accepted answer mentions running a method on a shell using a .dll. The second answer contains C# code, a commenter then asked basically what I want to know (how to modify the properties of a particular file), and the next commenter responded with “you can’t set these”…so I’m still at square 1.
Update 2: I also tried the following:
foreach (Object selectedObject in explorer.Selection)
{
Outlook.MailItem email = (selectedObject as Outlook.MailItem);
//Modify the information about the email
email.To = "I filled in To";
email.SaveAs(filename, OlSaveAsType.olMSG);
}
This code successfully grabs the selected email(s) and save them under filename. However, the email.To = “I filled in To” changes the information when you open the .msg, but not the file properties.
This cannot be changed, because it actually is not any file property in the terms of the filesystem (like file creation or modification datetime).
Columns in Windows Explorer you are talking about are “virtual” and they are “only” the feature of Windows Explorer. It “understand” content of some file types and it can handle showing and sorting columns like that.
If you want to change To, From etc. you have to change the content of the file you are saving, i.e. change the To or From in the message.
To do so, if You have an Microsoft.Office.Interop.Outlook.MailItem object (which you are just saving), set desired properties on that object before you save it to file, i.e.:
I don’t know if it also changes email stored in the Outlook, if it so, create a copy of the email before changing properties