我需要顯示安裝在網絡中的打印機。我使用下面的代碼來顯示打印機,但在本地它顯示網絡打印機,但在IIS中託管時,它不顯示網絡打印機(僅顯示本地打印機)。如何在ASP.NET中獲取網絡打印機
代碼-1:
ApplicationPrinter printer = new ApplicationPrinter();
ddlPrinters.DataSource = printer.InstalledPrinters();
ddlPrinters.DataBind();
ddlPrinters.SelectedItem.Text = printer.DefaultZebraPrinter();
代碼-2:
ddlPrinters.Items.Clear();
try
{
// Use the ObjectQuery to get the list of configured printers
ObjectQuery oquery =
new ObjectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher mosearcher =
new ManagementObjectSearcher(oquery);
ManagementObjectCollection moc = mosearcher.Get();
foreach (ManagementObject mo in moc)
{
PropertyDataCollection pdc = mo.Properties;
foreach (PropertyData pd in pdc)
{
if ((bool)mo["Network"])
{
ddlPrinters.Items.Add(mo["Name"].ToString());
break;
}
}
}
}
catch (ManagementException ex)
{
string msgDesc = string.Empty;
string script = string.Empty;
msgDesc = ex.Message;
script = "<script language=\"javascript\">alert('" + msgDesc + "'); </script>";
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "UserMessage", script, false);
}
這裏如果((布爾)MO [ 「網絡」])被用於僅顯示網絡打印機。
有沒有辦法在ASP.NET中獲取網絡打印機?
您是否期望代碼(在服務器上運行)能夠查看客戶端的打印機?那不會發生。 – 2011-02-14 10:20:08