我正在使用下面的代码从数据库中获取文件并使用从下拉列表中填充的已安装打印机中选择的打印机打印它,我的问题是在使用Printjob.Start()期间它抛出异常系统找不到指定的文件
我的代码是,
protected void ggvqpdetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToUpper().ToString() == "PRINTREC")
{
try
{
// Set the printer to a printer in the dropdown box when the selection changes.
PrintDocument printDoc = new PrintDocument();
string a = TextBox1.Text + TextBox2.Text + TextBox3.Text;
DataSet ds = ExamManagement.SP.Eval_QP_PrintSelect(a).GetDataSet();
if (ddlprint.SelectedIndex != -1 && ds.Tables[0].Rows.Count > 0)
{
// The dropdown box's Text property returns the selected item's text, which is the printer name.
printDoc.PrinterSettings.PrinterName = ddlprint.Text;
Process printJob = new Process();
printJob.StartInfo.FileName = ds.Tables[0].Rows[0]["Data"].ToString();
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printJob.StartInfo.Arguments = ddlprint.Text;
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(ds.Tables[0].Rows[0]["Data"].ToString());
printJob.Start();
}
}
catch(Exception ex)
{
Lblmsg.Visible = true;
Lblmsg.Text = ex.Message;
}
}
}