Windowsフォームアプリで、デフォルトのアプリケーションを使用して任意のファイルをXPSに出力するメソッドを作成しようとしています. これは正常に動作しますが、出力先の XPS パスをプリンターに渡すことができず、ファイルを開くダイアログが常に表示されます。FindWindow interrop を使用しない提案は役に立ちます。
ありがとうございました!
private void PrintXps(string printFilePath, string destinationXps){
var printJob = new Process();
printJob.StartInfo.FileName = filePath;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
var xps = PrinterSettings.InstalledPrinters.Cast<string>().First(p => p.ToLower().Contains("xps"));
printJob.StartInfo.Arguments = string.Format("\"{0}\"", xps);
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(filePath);
try
{
printJob.Start();
printJob.WaitForExit();
}
catch (Win32Exception ex)
{
MessageBox.Show("File is not supported. ");
}
}