protected void ggvqpdetail_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.ToUpper().ToString() == "PRINTREC") { try { string a = TextBox1.Text + TextBox2.Text + TextBox3.Text; DataTable dt = new DataTable(); IDataReader dr = ExamManagement.SP.Eval_QP_PrintSelect(a).GetReader(); dt.Load(dr); dr.Close(); dr.Dispose(); Byte[] data = (Byte[])dt.Rows[0]["Data"]; if (ddlprint.SelectedIndex != -1 && dt.Rows.Count > 0) { if (dt.Rows[0]["Type"].ToString() == "application/pdf") { PrintFormPdfData(data); } else if (dt.Rows[0]["Type"].ToString() == "application/vnd.ms-word") { PrintFormWordData(data); } } } catch(Exception ex) { ClientMessaging(ex.Message); } } } private void PrintFormPdfData(byte[] formPdfData) { string tempFile; tempFile = Path.GetTempFileName(); using (FileStream fs = new FileStream(tempFile, FileMode.Create)) { fs.Write(formPdfData, 0, formPdfData.Length); fs.Flush(); } try { string gsArguments; string gsLocation; ProcessStartInfo gsProcessInfo; Process gsProcess; gsArguments = string.Format("/h /t \""+ddlprint.SelectedItem.ToString()+"\" \"{0}\"", tempFile); gsLocation = @"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"; gsProcessInfo = new ProcessStartInfo(); gsProcessInfo.WindowStyle = ProcessWindowStyle.Hidden; gsProcessInfo.FileName = gsLocation; gsProcessInfo.Arguments = gsArguments; gsProcess = Process.Start(gsProcessInfo); gsProcess.WaitForExit(); gsProcess.Kill(); } finally { File.Delete(tempFile); } } private void PrintFormWordData(byte[] formWordData) { string tempFile; tempFile = Path.GetTempFileName(); using (FileStream fs = new FileStream(tempFile, FileMode.Create)) { fs.Write(formWordData, 0, formWordData.Length); fs.Flush(); } try { string gsArguments; string gsLocation; ProcessStartInfo gsProcessInfo; Process gsProcess; gsArguments = string.Format("/h /t \"" + ddlprint.SelectedItem.ToString() + "\" \"{0}\"", tempFile); gsLocation = @"C:\Program Files\Microsoft Office\OFFICE11\WINWORD.exe"; gsProcessInfo = new ProcessStartInfo(); gsProcessInfo.WindowStyle = ProcessWindowStyle.Hidden; gsProcessInfo.FileName = gsLocation; gsProcessInfo.Arguments = gsArguments; gsProcess = Process.Start(gsProcessInfo); gsProcess.WaitForExit(); gsProcess.Kill(); } finally { File.Delete(tempFile); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)