网页端调用当地应用打开当地文件(PDF、Word、excel、PPT)
一、配景原因根据欣赏器的安全计谋,在网页端无法直接打开当地文件,所以必要开发者曲线救国。
二、实现步调
前期预备:
确保已安装好可以打开文件的应用软件,如,WPS;
把要打开的文件统一放在一个文件夹,如,在D盘创建文件夹【文件夹名】。
1. 创建Windows应用程序—callexe
namespace callexe
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string strNew = args.Substring(10);
string utoSs = System.Web.HttpUtility.UrlDecode(strNew);
// 直接打开目录
string v_OpenFolderPath1 = @"D:/文件夹名/";
string v_OpenFolderPath = string.Concat(v_OpenFolderPath1, utoSs);
// 直接打开指定的文件
System.Diagnostics.Process.Start(v_OpenFolderPath);
Application.Exit();
}
}
}
2. 创建openfile.reg文件。
为了方便编辑文件,先创建openfile.txt文件,编辑完成后修改文件后缀为.reg,然后双击打开。
.reg:windows操作系统的注册表脚本文件。
创建open-exe文件夹并放在D盘,把callexe文件和openfile.reg放在open-exe内里。
Windows Registry Editor Version 5.00
@="URL:OPENFILE"
"URL Protocol"="D:\\open-exe\\callexe\\bin\\Debug\\callexe.exe"
@="D:\\open-exe\\callexe\\bin\\Debug\\callexe.exe,1"
@="D:\\open-exe\\callexe\\bin\\Debug\\callexe.exe %1" 3. 在前端调用
window.open("crealife1:xxx.pdf"); 详细原理以后慢慢增补。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]