I have problems printing to a network printer. The code below works fine on my own laptop and from Visual Studio, but when the site is run on an IIS 8 website (on Windows Server 2008 R2), clicking the printer buttons does nothing.. the page just starts loading (loads forever and times out), but nothing happens and no jobs are added to the printer's queue..
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int i = 0;
foreach (string s in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
Button b = new Button();
b.ID = "Print_" + i;
b.Text = s.ToString();
b.Click += b_Click;
test.Controls.Add(b);
i++;
}
}
void b_Click(object sender, EventArgs e)
{
string printer = ((Button)sender).Text;
PrintDocument p = new PrintDocument();
p.PrinterSettings.PrinterName = printer;
p.PrintPage += p_PrintPage;
p.Print();
}
void p_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("testpage", new System.Drawing.Font("Arial", 12), Brushes.Black, new PointF(200, 200));
}
}