简体   繁体   English

当我们将默认浏览器设置为chrome(除IE之外)时,从Windows应用程序打印html文件不起作用

[英]Printing html file from windows application is not working when we set default browser as chrome (other than IE)

I have to print html file when user clicks on print button and it is working fine (prompts print dialog) when I set default browser as IE. 当我将默认浏览器设置为IE时,我必须在用户点击打印按钮时打印html文件并且工作正常(提示打印对话框)。 If I change default browser to chrome or firefox other than IE, the code does not prompting print dialog instead it just opens html file in the browser. 如果我将默认浏览器更改为除IE之外的chrome或firefox,则代码不会提示打印对话框,而只是在浏览器中打开html文件。 Can you please let me know what configuration I have missed in the below code? 你可以告诉我在下面的代码中我错过了什么配置吗?

            string TempFile = @"D:\test.html";    

            ProcessStartInfo Params = new ProcessStartInfo();
            Params.FileName = "iexplore.exe";
            Params.Arguments = TempFile;
            Params.UseShellExecute = false;
            Params.Verb = "print";
            Params.WindowStyle = ProcessWindowStyle.Hidden;
            Params.CreateNoWindow = true;
            Process.Start(Params);

Finally I got the solution for this issue. 最后我得到了这个问题的解决方案。 The below code works like a charm!! 以下代码就像一个魅力!

using (Process exeProcess = new Process())
{
    string TempFile = @"D:\test.html";
    exeProcess.StartInfo.FileName = "rundll32";
    exeProcess.StartInfo.Arguments = @"system32\mshtml.dll,PrintHTML """ + TempFile + @"""";
    exeProcess.StartInfo.UseShellExecute = true;
    exeProcess.Start();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebBrowser上的HTML5的运行速度比IE或其他浏览器慢 - HTML5 on WebBrowser works slower than IE or other browser 使用 SHDocVw 时区分 IE 窗口和其他窗口 - Distinguishing IE windows from other windows when using SHDocVw 如何为网络浏览器默认设置IE9? - How to set IE9 by default for web browser? 从主窗体以外的窗体退出Windows窗体应用程序 - Exiting a windows form application from a form other than the main form 从Windows服务打印时,CreateProcessAsUser不使用LogonUser令牌 - CreateProcessAsUser not working with LogonUser token when printing from a Windows Service Selenium C#-与Chrome浏览器相比,使用IE11时,FindElemnt方法的执行速度较慢 - Selenium c# - The FindElemnt method perform slow when working with IE11 compared to Chrome browser 使用文件中的html启动默认浏览器,然后跳转到特定锚点 - Launching default browser with html from file, then jump to specific anchor 在Windows 8桌面应用程序的默认浏览器中打开URL - Opening a URL in the default browser in a Windows 8 desktop application Windows RegKey - 默认浏览器应用程序路径 - Windows RegKey - Default Browser Application Path 如何将默认浏览器设置为我的应用程序? - How to set the default browser to my application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM