问题描述
当我点击sharepoint 2010中的按钮时,我想获取已安装打印机的列表。
我已经在C#应用程序中编写代码以获取打印机列表。在这种情况下,我得到所有在列表中安装了打印机。请在C#应用程序中找到以下代码。
System.Management.ManagementScope objMS = new System.Management.ManagementScope(ManagementPath。 DefaultPath);
objMS.Connect();
SelectQuery objQuery = new SelectQuery(SELECT * FROM Win32_Printer);
ManagementObjectSearcher objMOS = new ManagementObjectSearcher(objMS,objQuery);
System.Management.ManagementObjectCollection objMOC = objMOS.Get();
foreach(ManagementObject Printers in objMOC)
{
if(Convert.ToBoolean(Printers [Default]))// LOCAL PRINTERS。
{
cmbLocalPrinters.Items.Add(打印机[名称]);
}
// if(Convert.ToBoolean(Printers [Local] ))//本地打印机。
// {
// cmbLocalPrinters.Items.Add(打印机[名称]);
//}
// if(Convert.ToBoolean(Printers [Network]))//所有网络打印机。
// {
// cmbNetworkPrinters.Items.Add(打印机[名称]);
//}
}
但是当我在sharepoint项目中编写相同代码时,我没有安装打印机列表。请帮助我...
我添加了一个Sharepoint项目中的可视化Web部件然后在该Web部件上我添加了一个列表框和按钮,单击该按钮我编写了我的代码。当我在dot net web应用程序上编写相同的代码时我得到所有已安装的打印机列表。但在sharepoint项目中,我没有得到打印机列表只发送注释和xps文档显示
I want to get the list of installed printers when i am clicking the button in sharepoint 2010.
I have written the code in C# application for getting printers list.In this case I am getting all installed printers in the list.Please find the below code which I have written in C# application
System.Management.ManagementScope objMS = new System.Management.ManagementScope(ManagementPath.DefaultPath);
objMS.Connect();
SelectQuery objQuery = new SelectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher objMOS = new ManagementObjectSearcher(objMS, objQuery);
System.Management.ManagementObjectCollection objMOC = objMOS.Get();
foreach (ManagementObject Printers in objMOC)
{
if (Convert.ToBoolean(Printers["Default"])) // LOCAL PRINTERS.
{
cmbLocalPrinters.Items.Add(Printers["Name"]);
}
//if (Convert.ToBoolean(Printers["Local"])) // LOCAL PRINTERS.
//{
// cmbLocalPrinters.Items.Add(Printers["Name"]);
//}
//if (Convert.ToBoolean(Printers["Network"])) // ALL NETWORK PRINTERS.
//{
// cmbNetworkPrinters.Items.Add(Printers["Name"]);
//}
}
But same code when I am written in sharepoint project, there I am not getting installed printers list.Please help me...
I have added a visual web part in Sharepoint project and then on that web part I have added one list box and button and on click of that button I have written my code.When same code I am writing on my dot net web application I am getting all installed printers list.But in sharepoint project I am not getting that printers list only send note and xps document are displaying
推荐答案
这篇关于使用Sharepoint 2010获取已安装打印机的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!