我有以下代码来下载.xls格式的电子邮件附件。
Application app = new Application();
NameSpace ns = app.GetNamespace("MAPI");
string recipientName = "aaa.bbb@ccccccc.xx";
Recipient recip = ns.CreateRecipient(recipientName);
recip.Resolve();
if (recip.Resolved)
{
MAPIFolder inboxFolder = ns.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderInbox);
Items items = (Items)inboxFolder.Items;
items = items.Restrict("[Unread] = true");
foreach (MailItem eMail in items)
{
string Subject = eMail.Subject;
if (Subject == "xxxxxxxxx")
{
if (eMail.Attachments.Count > 0)
{
for (int i = 1; i <= eMail.Attachments.Count; i++)
{
eMail.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + eMail.Attachments[i].FileName);
}
}
}
}
}
一切正常,但是当我尝试打开xls文件时,它会显示该文件的文件格式与文件扩展名指定的文件格式不同。
我看到附件被下载为单个文件网页,是否有任何技巧以真正的.xls格式保存?