?
Solved

Printing in C#

Posted on 2006-05-30
9
Medium Priority
?
1,335 Views
Last Modified: 2008-01-09
Hello Experts,

I am using this code:

-------------------------------------

public bool PrintReport(string ReportPath)
            {
                  this.RenderedReport = this.RenderReport(ReportPath);
                  try
                  {
                        if (m_numberOfPages < 1)
                        {
                              return false;
                        }
                        PrinterSettings printerSettings = new PrinterSettings();
                        string pkInstalledPrinters;

                        //PageSettings objprinter = new PageSettings();
                        //object strname = objprinter.PrinterSettings.PrinterName;

                        pkInstalledPrinters = printerSettings.PrinterName;                        
                        printerSettings.PrinterName =       pkInstalledPrinters;       
                        

                        printerSettings.MaximumPage = m_numberOfPages;
                        printerSettings.MinimumPage = 1;
                        printerSettings.PrintRange = PrintRange.SomePages;
                        printerSettings.FromPage = 1;
                        printerSettings.ToPage = m_numberOfPages;
                        
                        PrintDocument pd = new PrintDocument();
                        printerSettings.PrinterName = pd.PrinterSettings.PrinterName;

                        m_currentPrintingPage = 1;
                        m_lastPrintingPage = m_numberOfPages;
                        pd.PrinterSettings = printerSettings;
                        Console.WriteLine("Printing report...");
                        pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);

                        pd.Print();
                  }
                  catch (Exception ex)
                  {
                        Console.WriteLine(ex.Message);
                  }
                  finally
                  {
                  }
                  return true;
            }


------------------------------------

I am getting this message when i debug:

printerSettings.PrinterName =       "<no default printer>"      string

any idea?  I have a printer with default on my local machine.

Thanks

0
Comment
Question by:mani_sai
9 Comments
 
LVL 2

Expert Comment

by:MyersA
ID: 16791741
Hi mani_sai,

If you add a breakpoint to the line:
pkInstalledPrinters = printerSettings.PrinterName;                    

and check its value of printerSettings.PrinterName at that point, do you get a valid name?
Also, did you double-check that in the Windows 'Printers and Faxes' menu you have a printer marked with the black checkmark?

Vaughn
0
 
LVL 8

Author Comment

by:mani_sai
ID: 16791768
Vaughn-Thanks for your reply.

I set a break point and got this value:

printerSettings.PrinterName =      "<no default printer>"     string

also i checked in Windows 'Printers and Faxes'

i have a printer marked with black checkmark.

any idea?

0
 
LVL 8

Author Comment

by:mani_sai
ID: 16791934
The same code was working before, suddenly it is not getting default printer name.

I reinstalled the network printer and made it default, still the same issue.

any idea?

Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16792114
What does printerSettings.InstalledPrinters.Count return?

Bob
0
 
LVL 8

Author Comment

by:mani_sai
ID: 16792246
printerSettings.InstalledPrinters.Count()

returns 0.

0
 
LVL 8

Author Comment

by:mani_sai
ID: 16792284
also if i hard code the printer name, it is working fine.

printerSettings.PrinterName = "Xerox DocuPrint N40";


0
 
LVL 2

Accepted Solution

by:
MyersA earned 1500 total points
ID: 16792634
Are you using it in a Web Form or Control?

I found a post with a problem similar to yours where the user tries to fill a combobox with all the available network printers (he had four installed), but InstalledPrinters didn't find any.
Here's the link:
http://www.dotnet247.com/247reference/msgs/30/153207.aspx

Hope this helps,
Vaughn
0
 
LVL 8

Author Comment

by:mani_sai
ID: 16895301
Thanks for your link, it is security issue with IIS.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question