Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server C#4.0
I have a MS SQL DB Table which stores the File Name and the Data of that file. In the Client-Side I want the client to fetch the file from the database and print it with the Printer Selected from the List of Installed Printers from the Dropdownlist, I had tried in many options and Code snippets for reading the file and printing it but it is not working Can anyone help me out with this ?
 
I tried with the Following Code,
 
 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;
                    DataTable dt = new DataTable();
                    IDataReader dr = ExamManagement.SP.Eval_QP_PrintSelect(a).GetReader();
                    dt.Load(dr);
                    dr.Close();
                    dr.Dispose();
                    if (ddlprint.SelectedIndex != -1 && dt.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;
 
                        ProcessStartInfo printJob = new ProcessStartInfo();
                        printJob.FileName = dt.Rows[0]["Filename"].ToString();
                        
                        printJob.UseShellExecute = true;
                        printJob.Verb = "printto";
                        printJob.CreateNoWindow = true;
                        printJob.WindowStyle = ProcessWindowStyle.Hidden;
                        printJob.Arguments = ddlprint.Text;//Getting Which Printer
                        
                        Process.Start(printJob);
                        if(dr.Read())
                        {
 
                        }
                        
                    }
                }
                catch(Exception ex)
                {
                    Lblmsg.Visible = true;
                    Lblmsg.Text = ex.Message;
                }
            }
        }
Posted 28-May-13 1:53am
Edited 28-May-13 3:04am
v2
Comments
CHill60 at 28-May-13 8:01am
   
You say "it is not working" but you have not posted the code that you have tried, nor said how it is not working. Use the improve question link to provide the missing detail
yloginov at 28-May-13 10:42am
   
are you getting an exception when you run that code? If so, you should post it so people can understand what "not working" means.
Member 9903922 at 29-May-13 0:02am
   
@yloginov I am getting the "Specified file Not Found" Win32 Exception
yloginov at 29-May-13 7:57am
   
Are you sure the file exists?
For this line of code
printJob.FileName = dt.Rows[0]["Filename"].ToString();
try hardcoding the file name to the one that you know exists for sure and test your code again. So change the code above to something like this,
printJob.FileName = @"c:\my_test_file.txt";
 
Member 9903922 at 29-May-13 8:06am
   
@yloginov I am very much sure that file exists, instead of using FileName I had tried in with Storing the retrivied data in a Temporary file and Printing (the may be PDF or Word) but PDF Reader or MS Word App showed file not found error I had posted the Error in http://www.codeproject.com/Questions/599728/ProblemplusofplusPrintingplustheplusfileplusRetrie

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 Maciej Los 280
2 Afzaal Ahmad Zeeshan 224
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 28 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100