我正在尝试拼凑一小段控制台代码,以通过 Internet Explorer 将文件夹中的一些 HTML 文件打印到默认打印机。我从http://weblogs.asp.net/israelio/archive/2004/06/23/162913.aspx找到了以下代码,这似乎几乎适合我的需求。
我做了一些改动,但我的编程技能非常有限。我正在寻找一些帮助以确保语法正确,并且有人向我展示如何通过 Internet Explorer 静默打印,而不是像我现在所相信的那样打开 Internet Explorer。
任何帮助将不胜感激...
using System
using System.IO
// How much deep to scan. (of course you can also pass it to the method)
const int HowDeepToScan=4;
public static void ProcessDir(string sourceDir, int recursionLvl)
{
if (recursionLvl<=HowDeepToScan)
{
// Process the list of files found in the directory.
string [] fileEntries = Directory.GetFiles(@"C:\fileDump\", "*.html");
foreach(string fileName in fileEntries)
{
// do something with fileName
System.Diagnostics.Process.Start(fileName);
}
// Recurse into subdirectories of this directory.
string [] subdirEntries = Directory.GetDirectories((@"C:\fileDump);
foreach(string subdir in subdirEntries)
// Do not iterate through reparse points
if ((File.GetAttributes(subdir) &
FileAttributes.ReparsePoint) !=
FileAttributes.ReparsePoint)
ProcessDir(subdir,recursionLvl+1);
}
}