开发者

Converting all attachments of an Outlook email to PDF

开发者 https://www.devze.com 2023-02-03 13:56 出处:网络
I\'m in the process of writing an Add-in for Outlook07 which should store the text of an email and all it\'s attachments in separate pdf files. Of course this is only for reasonable attachments, it wo

I'm in the process of writing an Add-in for Outlook07 which should store the text of an email and all it's attachments in separate pdf files. Of course this is only for reasonable attachments, it would not make sense for zip files and such.

I got to the point where all files are stored in a temp dir (for each mail). The mail itself is easily converted but i'm having trouble with the attachments.

The idea is to use the exportAs method from each corresponding office interop, so i do not have to install aditional software on client pcs.

To export each file with it's corresponding office application I first have to find out which office application can open it. Sure, the first thing that comes to mind is trying out the extensions but there has to be some more efficient way then

if(fileExt == "doc" or "docx" or "wordformat i forgot") Open Word and Convert
if(fileExt == "xls") Open Excel and Convert

I've tried to find something in the msdn documentations and google but Office.Interops are REALLY badly documented which made it already hard to get where I am now. And opening documents in the above sense isn't covered anywhere.

Any hint at all would make me really happy.

EDIT - following is the example how i convert word documents:

Word.Application wordApp = new Word.Application();
object oFilename = filename + ".html";
wordApp.Documents.Open(ref oFilename, x,x,x,x,x,x);
wordApp.ActiveDocument.ExportAsFixedFormat(filename+".pdf",
Word.WdExportFormat.wdExportFormatPDF,x,x,x,x,x);
wordApp.ActiveDocument.Close();
wordApp.Close();
wordApp = null;

EDIT - the road to success:

var key = registry.ClassesRoot.OpenSubKey(Path.GetExtension(filename));
string openType = key.GetValue("").ToString().ToLow开发者_开发百科er();

if(openType.StartsWith("word.")) return DocumentType.Word;
if(openType.StartsWith("excel.")) return DocumentType.Excel;

return DocumentType.Unusable;

It's looking good. Thx for the help, great way to start into the weekend.


The best thing to do would be to use the registry to find out what application is associated with the extension. If you have a look at this link:

Script to associate an extension to a program

It shows where in the registry you need to look.

0

精彩评论

暂无评论...
验证码 换一张
取 消