Process.start在IIS中无法从Web应用程序打印? [英] Process.start not working in IIS for printing from web application?

查看:96
本文介绍了Process.start在IIS中无法从Web应用程序打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的网页表格中有一个打印按钮,它会将Label.txt文件发送到打印机。为此,我正在创建一个流程并设置如下属性。





这在我的本地工作正常,但当我主持它在IIS上它显示错误,例如,



Hi All,

I have a print button in my web form which will send the Label.txt file to the printer. For that i am creating a process and sets the properties as below.


This is working fine in my local but when i host it on IIS it shows error like,

No application is associated with the specified file for this operation

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation

Source Error: 


Line 350:            Process p = new Process();
Line 351:            p.StartInfo = info;
Line 352:            p.Start();
Line 353:            if (!p.HasExited)
Line 354:               p.WaitForInputIdle();

can anyone help? any other way to print data for my requirement?
thanks in advance.

What I have tried:

<pre>ProcessStartInfo info = new ProcessStartInfo();
            if (prName != "")
            {
                info.Arguments = "\"" + prName + "\"";
            }
            info.Verb = "PrintTo";
            info.FileName = Server.MapPath("~/Label.txt");
            info.CreateNoWindow = true;
            info.WindowStyle = ProcessWindowStyle.Hidden;


            Process p = new Process();
            p.StartInfo = info;
            p.Start();
            if (!p.HasExited)
               p.WaitForInputIdle();
            System.Threading.Thread.Sleep(3000);
            try
            {
                if (false == p.CloseMainWindow())
                    p.Kill();
            }
            catch (Exception ex) { }

推荐答案

即使你不告诉我们你是什么文件想要打印,根据错误信息很清楚发生了什么...

Even you do not tell us what file do you want to print, it is pretty clear what happening, based on the error message...
引用:

否应用程序与此操作的指定文件相关联

No application is associated with the specified file for this operation

您正在尝试打印一个没有应用程序关联的文件...

,例如,如果您没有Word(或其他文字处理应用程序)安装在您的服务器上)并尝试打印DOCX文件,您将失败,因为没有与该类型相关联的应用程序和操作系统不知道如何处理它...

You are trying to print a file that no application associated with...
for instance if you had no Word (or other word processing application installed on your server) and try to print a DOCX file, you will fail as no application associated with the type and the OS does not know how to handle it...


您的代码是在服务器上运行 。即使它确实有效,它也会将文件打印到连接服务器的默认打印机。



它可能出现以便工作在Visual Studio中进行调试。但这只是因为,在那个特定的例子中,客户端和服务器是同一台计算机。



在用户的打印机上打印东西的唯一方法是使用Javascript < a href =https://developer.mozilla.org/en-US/docs/Web/API/Window/print> window.print()方法 [ ^ ]。您需要在页面上显示文本文件的内容,注册一个脚本以调用 window.print(),然后使用CSS打印样式 [ ^ ]控制打印输出中显示的内容。
Your code is running on the server. Even if it did work, it would print the file to the default printer connected the server.

It might have appeared to work when you were debugging in Visual Studio. But that's only because, in that particular instance, the client and server were the same computer.

The only way to print something on the user's printer is with the Javascript window.print() method[^]. You will need to display the contents of the text file on the page, register a script to call window.print(), and use CSS print styles[^] to control what appears in the printed output.


这篇关于Process.start在IIS中无法从Web应用程序打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆