[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string Name);
private void Print_Click(object sender, EventArgs e)
{
try
{
//設定針測的檔案類型,如不指定可設定*.*
string strFilePath = @"C:\inetpub\wwwroot\TEST\Report\PdfPrint\";
FileSystemWatcher watch = new FileSystemWatcher(strFilePath, "*.pdf");
//開啟監聽
watch.EnableRaisingEvents = true;
//新增時觸發事件
watch.Created += watch_Created;
Print.Enabled = false;
}
catch (Exception ex)
{
}
}
private void watch_Created(object sender, FileSystemEventArgs e)
{
try
{
string DirectPath = e.FullPath;
//如果偵測到為檔案,則依路徑對此料夾做檔案處理
if (File.Exists(DirectPath))
{
//string s = @"C:\inetpub\wwwroot\SalesAppTest\Report\PdfPrint\07031_CEM20180100569_JENNY.pdf";
int intIndex = DirectPath.IndexOf("_");
string strPrintName = DirectPath.Substring(48, intIndex - 48);//string s = @"C:\inetpub\wwwroot\SalesAppTest\Report\PdfPrint\
string strFileName = DirectPath.Substring(48, DirectPath.Length - 48);
SetDefaultPrinter(strPrintName);
//begin
System.Diagnostics.ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = @"C:\Users\Administrator\Documents\visual studio 2012\Projects\WinDirectPrint\WinDirectPrint\FoxitReaderPortable\FoxitReaderPortable.exe";
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.Arguments = @"/p /h " + DirectPath;
Process p = new Process();
p.StartInfo = info;
p.Start();
//end
}
}
catch (Exception ex)
{
}
}
沒有留言:
張貼留言