简体   繁体   中英

Printing .msg files client-side using VBScript in a HTML page

I am trying to write a feature for our SharePoint farm that lets users tick items in a document library, choose a custom action 'Print' from the ribbon and then print out the documents client side. Most of the documents print fine - (.docx, .xlsx, .pdf), as I can use ActiveXObjects with Print methods for each of these types. However, there is no ActiveXObject for Outlook that allows easy printing of .msg files. As a result, the only method I have found for printing .msg files client side through script is by vbs:

TargetFolder = "C:\EmailExport" 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items
For Each objItem in colItems
    objItem.InvokeVerbEx("Print")
Next

This works fine in a .vbs file on my local machine, but the minute I try and place it in a .html file for testing in browser, it gives me a Permission Denied error. I am not in a situation where I can modify the security levels for Internet Explorer as the company's group policies control them.

The test .html page is like this:

<html>
<head>
<script language="vbscript">
<!--
TargetFolder = "C:\EmailExport"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For Each objItem in colItems
       objItem.InvokeVerbEx("Print")
Next
-->
</script>
</head>
<body>
</body>
</html>

Does anybody have any solutions that will let me print out these .msg files client-side? I want to maintain the format that outlook prints them out in, so converting them to text files etc first isn't really an option...

You cannot access the Namespace method from within the browser environment for security reasons. (A webpage should never have a need to access local data directories.) You would need to run this as a stand-alone script through the Windows Script Host.

我尝试了您的脚本,该脚本可以在HTML页面上运行,但是只有当您使用Internet Explorer作为浏览器并且用户需要在其PC上具有足够的权限并且需要将IE的安全设置设置为启用Active-X时,该脚本才能工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM