我正在开发文档管理Intranet应用程序。文件将位于共享网络驱动器上;用户将单击链接,该文件将在其本机应用程序(Outlook,Word,Excel等)中打开。除了eml,我使用ActiveX打开了所有Office文件。当我尝试在Outlook 2010中打开eml文件时,在IE中调试时出现无效的路径错误。
这是链接html:
<a class="documentLink" href="file:///E:\FileShareDocs\996-0-Client\test 107 Copy.eml">test 107 Copy</a>
和js:
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
$('.documentLink').click(function () {
var app;
var path = $(this).attr('href');
var extension = path.split('.').pop();
switch(extension) {
case "docx":
case "doc":
case "rtf":
app = "Word.Application";
try {
var objword = new ActiveXObject(app);
} catch (e) {
alert(e);
}
if (objword != null) {
objword.Visible = true;
objword.Documents.Open(path);
}
break;
case "xlsx":
case "xls":
app = "Excel.Application";
try {
var objexcel = new ActiveXObject(app);
} catch (e) {
alert(e);
}
if (objexcel != null) {
objexcel.Visible = true;
objexcel.Workbooks.Open(path);
}
break;
case "pptx":
case "ppt":
app = "PowerPoint.Application";
try {
var objppt = new ActiveXObject(app);
} catch (e) {
alert(e);
}
if (objppt != null) {
objppt.Visible = true;
path = path.substring(8, path.length);
objppt.Presentations.Open(path);
}
break;
case "msg":
case "eml":
app = "Outlook.Application";
try {
var objoutlook = new ActiveXObject(app);
var objNS = objoutlook.GetNameSpace('MAPI');
} catch (e) {
alert(e);
}
if (objoutlook != null) {
path = path.substring(8, path.length);
var mailItm = objoutlook.Session.OpenSharedItem(path);
mailItm.Display();
}
break;
case "tiff":
case "tif":
case "pdf":
app = "AcroExch.AVDoc";
try {
var objacro = new ActiveXObject("AcroExch.App");
var objpdf = new ActiveXObject(app);
} catch (e) {
alert(e);
}
if (objacro != null && objpdf != null) {
path = path.substring(8, path.length);
objpdf.Open(path,$(this).html());
objacro.Show();
}
break;
case "txt":
case "htm":
path = path.substring(8, path.length);
var shell = new ActiveXObject("WScript.shell");
var command = "NOTEPAD.EXE " + path;
shell.run(command, 3);
//document.execCommand("SaveAs",true,path);
break;
default:
//Open file's containing folder in explorer
path = path.substring(8, path.length);
path = path.substring(0, path.lastIndexOf('\\'));
var shell = new ActiveXObject("WScript.shell");
var command = "explorer " + path;
shell.run(command, 3);
}
});
}
我已经尝试评论下面的行,这将留下&#39; file:///&#39;在路径中,但IE仍然会抛出一个错误,说它无法找到该文件。
path = path.substring(8, path.length);
答案 0 :(得分:1)
Outlook不通过其对象模型提供任何与MIME(EML)相关的功能。你可以
使用IConverterSession内置MAPI接口 - 它只能用于C ++或Delphi,而不能用于Java Script
自行解析EML文件
使用Redemption - 它将允许您使用RDOSession。CreateMesageFromMSGFile创建临时MSG文件,然后使用RDOMail导入EML文件。导入后跟RDOMail.Display。
另外,如果你要做的只是向用户显示EML文件,为什么不简单地创建一个WScript.Shell实例来调用Run()传递EML文件名作为参数?