• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2716
  • Last Modified:

ASP.NET: Install printer using VB.NET

Hi,

I would like to be able to create a gridview that list all network printer and have a user select there printer and have it automatically install instead of doing it manually.
0
asp_net2
Asked:
asp_net2
  • 7
  • 5
1 Solution
 
Sachintana DissanayakeSenior Web DeveloperCommented:
Use the following WMI query to retrieve printers in the network.
I am not sure whether this is working inside the web application.

System.Management.ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");

If this doesn't work for network printers, please follow the link below, you might need to convert this to .net code.
http://msdn2.microsoft.com/en-us/library/aa394363.aspx

This will help you to find any active directory as SQL queries, that't interesting.
http://www.thescripts.com/forum/thread508386.html

To add printer follow these reference.
http://msdn2.microsoft.com/en-us/library/aa384769(VS.85).aspx
0
 
asp_net2Author Commented:
sachintana,

I appreciate the help but not what I'm looking for. I'm looking for a way to click a link on a web form and have it install the printer from the link I click on.

Example:
HP LaserJet 4200 would be the link and when I click that link it would automaticlly install the printer as default with the appropriate IP address.
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
So you can get all the printers installed in your machine using .net code.
      http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printersettings.installedprinters.aspx

This sample demonstrate, how to set the printer in the PrintDocument object (printDoc).
            printDoc.PrinterSettings.PrinterName = comboInstalledPrinters.Text
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
asp_net2Author Commented:
I tried to copy and past the code that Microsoft has but no dice!
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
Does PopulateInstalledPrintersCombo() function works for you and populate the dropdown list?

Is it problem of printing.
How does your PrintDocument is creating from the code.
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
Here's a sample of how to use PrintDocument...
http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

Please share you code to see how you are printing it in .NET.
0
 
asp_net2Author Commented:
sachintana,

What i'm looking for is a way for users in a network to click on a link in an asp.net gridview that displays the printer within there office. Once the user selects the appriate printer then it will install the printer without them doing anything.
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
Are you clear with this code...

PopulateInstalledPrintersCombo() to populate network printers.

comboInstalledPrintersSelected() to print using selected printer in the dropdown.

   private void PopulateInstalledPrintersCombo()
    {
        // Add list of installed printers found to the combo box.
        // The pkInstalledPrinters string will be used to provide the display string.
        String pkInstalledPrinters;
        for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
        {
            pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
            comboInstalledPrinters.Items.Add(pkInstalledPrinters);
        }
    }
 
 
    private void comboInstalledPrintersSelected()
    {
        PrintDocument printDoc = new PrintDocument();
 
        // Set the printer to a printer in the combo box when the selection changes.
        if (comboInstalledPrinters.SelectedIndex != -1)
        {
            // The combo box's Text property returns the selected item's text, which is the printer name.
            printDoc.PrinterSettings.PrinterName = comboInstalledPrinters.Text;
            printDoc.Print();
        }
    }

Open in new window

0
 
asp_net2Author Commented:
sachintana,

How do I populate the printer now? I ran the code that you supplied and I added the namespace and a dropdown with the ID. The page runs fine but no printer where in the dropdown.
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
You have to first setup printers in windows (Control Panel).

0
 
asp_net2Author Commented:
sachintana,

I have 4 printers installed and neither are showing up in the dropdown. All, what i needed is a way for a user to click on the name of the printer of a location and have that printer that the user chooses install automatically without the user doing anything.
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
Did you test in your host machine? when code is running in the server, it will take Printers installed in the web server.

I don;t think you can get printer installed on user machine.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now