.NET:如何打印文件W / O打开它们 [英] .NET: How to print files w/o opening them

查看:195
本文介绍了.NET:如何打印文件W / O打开它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个基本的档案文件,我们给用户打印这些文件的可能性的应用程序。它们可以是.txt,doc和.PDF,的.jpg没有任何幻想。 有没有一种.NET的方式将这些文件发送到打印机,而不进一步处理它们,即打开它们?

We have an application that basically archives files and we give the user the possibility to print these files. They can be .txt, .doc, .pdf, .jpg nothing fancy. Is there a .NET way to send these files to the printer without handling them further, ie opening them?

我已经尝试过创建过程与StartInfo.Verb =打印

I already tried creating a process with the StartInfo.Verb = "print"

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = fileName;
p.StartInfo.Verb = "print"
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

p.Start();

它仍然打开,我不想要的文件。有人可以帮忙吗?

It still opens the file which I don't want. Can someone help?

任何帮助将是AP preciated。 托比

Any help would be appreciated. Tobi

推荐答案

我的理解是,大多数应用程序将打开(哪怕是暂时的),当你打印。试着右击MS Word文档,打打印。你会看到Word中打开,打印,并关闭。

My understanding is that most apps will open (even briefly) when you print. Try right-clicking a MS Word document and hitting print. You'll see Word open, print, and close.

不过,您可能想要将它添加到您的code,以保持过程隐蔽性和关闭时完成:

However, you might want to add this to your code to keep the process hidden and to close when finished:

p.Start();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (p.HasExited == false)
{
   p.WaitForExit(10000);
}

p.EnableRaisingEvents = true;
p.CloseMainWindow();
p.Close();

这篇关于.NET:如何打印文件W / O打开它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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