我有的
我目前正在编写一个程序,该程序采用指定的文件并对其执行一些操作。目前它会打开它,和/或将其附加到电子邮件中并将其邮寄到指定的地址。
该文件可以是以下格式:Excel、Excel 报告、Word 或 PDF。
我目前正在做的是使用文件路径生成一个进程,然后启动该进程;但是,我也在尝试修复我添加的错误功能,该功能将动词“PrintTo”添加到启动信息中,具体取决于指定的设置。
我需要的
我要完成的任务是我希望打开文档,然后将其打印到程序本身命名的指定打印机上。之后,文件应该会自动关闭。
如果没有办法通用地做到这一点,我们也许可以想出一种方法来为每个单独的文件类型做到这一点。
你需要什么
这是我正在使用的代码:
ProcessStartInfo pStartInfo = new ProcessStartInfo();
pStartInfo.FileName = FilePath;
// Determine wether to just open or print
if (Print)
{
if (PrinterName != null)
{
// TODO: Add default printer.
}
pStartInfo.Verb = "PrintTo";
}
// Open the report file unless only set to be emailed.
if ((!Email && !Print) || Print)
{
Process p = Process.Start(pStartInfo);
}
我过得怎么样...
仍然难倒......可能会像微软那样称呼它,“这是设计使然”。