我尝试使用类Process
进行打印,但出现此异常:
“此应用程序没有与指定文件关联的应用程序”
这是我的代码:
byte[] fileStresm = getFileStresm();
string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf");
File.WriteAllBytes(filePath, fileStresm );
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = filePath //put the correct path here
};
p.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
答案 0 :(得分:0)
需要添加此属性:
UseShellExecute = true
代码:
byte[] fileStresm = getFileStresm();
string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf");
File.WriteAllBytes(filePath, fileStresm );
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = filePath //put the correct path here
UseShellExecute = true
};
p.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}