Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 17-Apr-13 1:43am
v3

1 solution

 
Share this answer
 
Comments
PrachiMhatre 16-Apr-13 7:46am    
Not worked this solution as I am not getting Printers property of the Application object.
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900