DocumentItem.SaveAs导致文件损坏 [英] DocumentItem.SaveAs results in corrupted file
问题描述
在Outlook中,我在文件夹中有各种DocumentItem,例如收件箱,并且我试图在拖放事件中将它们保存到文件系统中.
Within outlook I have various DocumentItems in folders such as the inbox and I am trying to save these to the file system within a drag/drop event.
这是代码:
for (var i = 1; i <= _application.ActiveExplorer().Selection.Count; i++)
{
var temp = _application.ActiveExplorer().Selection[i];
var documentItem = (temp as DocumentItem);
if (documentItem == null)
continue;
var tempFileName = Path.GetTempPath() + documentItem.Subject;
documentItem.SaveAs(tempFileName);
}
它们似乎已成功保存并具有文件大小:
They seem to save successfully and have file sizes:
但是当我尝试打开其中的任何一个时,所有人都说无法打开它们,因此它们以某种方式损坏了,有人有任何想法吗?
But when I try to open any of them they all say they cannot be opened so they are corrupted somehow, does anyone have any ideas?
推荐答案
您在调用SaveAs时未指定格式,Outlook对象模型将其默认设置为olMsg.您最终得到一个带有JPG扩展名的MSG文件.
You are calling SaveAs without specifying the format, and Outlook Object Model defaults it to olMsg. You end up with an MSG file with a JPG extension.
您需要做的是循环遍历DocumentItem.Attachments集合中的所有附件并调用Attachment.SaveAsFile.您可能还需要使用Attachmeent.FileName属性.
What you need to do is loop though all attachments in the DocumentItem.Attachments collection and call Attachment.SaveAsFile. You might also want to use the Attachmeent.FileName property.
仅是一般性的评论-多点表示法是邪恶的,尤其是在厕所中:
Just a general comment - multiple dot notation is evil, especially in a loo:
Selection selection = _application.ActiveExplorer().Selection;
for (var i = 1; i <= selection.Count; i++)
{
var temp = selection[i];
var documentItem = (temp as DocumentItem);
...
这篇关于DocumentItem.SaveAs导致文件损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!