I am working on a document management intranet application. Files will be on a shared network drive; users will click on a link and that file will open in its native application (Outlook, Word, Excel, etc.). I have all of the Office files opening using ActiveX except for eml. When I try to open eml files in Outlook 2010, I get an invalid path error when debugging in IE.
Here is the link html:
<a class="documentLink" href="file:///E:\FileShareDocs\996-0-Client\test 107 Copy.eml">test 107 Copy</a>
and the 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);
}
});
}
I've tried commenting out the line below, which would leave the 'file:///' in the path, but IE still throws an error saying it cannot find the file.
path = path.substring(8, path.length);