当web应用程序主机位于本地服务器上时,如何通过asp.net c#中的代码直接将文件发送到打印机

当web应用程序主机位于本地服务器上时,如何通过asp.net c#中的代码直接将文件发送到打印机,c#,C#,当代码从VisualStudio运行时,此代码将起作用。 但当主机位于本地主机上时不工作。不要打电话给打印机 protected void btnsave_Click(object sender, EventArgs e) { try { objBel.BillId = lblbillid.Text; objBel.NetAmount = txtnetbillamt.Text;

当代码从VisualStudio运行时,此代码将起作用。 但当主机位于本地主机上时不工作。不要打电话给打印机

    protected void btnsave_Click(object sender, EventArgs e)
    {
        try
        {
            objBel.BillId = lblbillid.Text;
            objBel.NetAmount = txtnetbillamt.Text;
            objBel.PDiscount = txtdiscountpercentage.Text;
            objBel.DiscountA = txtdiscountamount.Text;
            objBel.TaxAmt = txttaxamount.Text;
            objBel.PaymentMode = ddlpaymentMode.SelectedItem.Text;
            if (ddlpaymentMode.SelectedItem.Text == "Cheque")
            {
                objBel.ChequeNo = txtchno.Text;
                if (txtDate.SelectedDate != null)
                {
                    objBel.ChequeDate = txtDate.SelectedDate.Value.ToString("dd-MM-yyyy");
                }
                objBel.ChequeDetails = txtotherdetails.Text;
            }
            if (rbyes.Checked)
            {
                objBel.ThirdParty = txtthirdpartydiscription.Text;
            }
            objBel.FinalAmt = txtfinalamount.Text;
            objBel.UserId = Convert.ToInt32(Session["UserId"]);
            objBel.Time = DateTime.Parse(DateTime.Now.ToString()).ToString("hh:mm tt");
            int i = objBal.UpdateBill(objBel);
            if (i > 0)
            {
                Session["Billid"] = "";           
                DataTable dt = new DataTable();
                dt = objBal.BillGenrate(lblbillid.Text);
                ReportDocument doc = new ReportDocument();
                doc.Load(Server.MapPath("~/CrystalReport/BillPrint.rpt"));
                doc.SetDataSource(dt);
                if (File.Exists(HttpContext.Current.Server.MapPath("\\Billprints\\Invoice.txt")))
                    File.Delete(HttpContext.Current.Server.MapPath("\\Billprints\\Invoice.txt"));
                string fileName = Server.MapPath("\\Billprints\\") + "Invoice.txt";
                doc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Text, fileName);
                doc.Refresh();
                doc.PrintToPrinter(1, false, 0, 0);


            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Error Occur Try Again !!')", true);

            }
        }
        catch { }
    }

PrintTopPrinter中的参数是什么?它们是否指已安装打印机的索引号?不同PC上的打印机安装顺序不一定相同。您知道这将打印到服务器上安装和配置的打印机,而不是与运行浏览器的机器相关的任何打印机,不是吗?