Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Bind list of printers

Hello All,

I have a requirement in advanced installer below

1. I need a custom action to get list of local & network printers.
2. Using the custom action i have bind the printers to combobox.

any help on the above...

Thanks in advance
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Bind list of printers

Hello and welcome to Advanced Installer forums,
1. I need a custom action to get list of local & network printers.
Indeed, to get the list of the local & network printers you need to create a custom action. Please take a look on the How to get the list of all printers in computer thread which debates this subject.
2. Using the custom action i have bind the printers to combobox.
To integrate your custom action in Advanced Installer, please take a look on the Options to integrate and debug custom actions article with related information for hints and guidance.

A sample code with the above functionality is the following:

Code: Select all

    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction1(Session session)
        {
            session.Log("Begin CustomAction1");

            const string SEP_2 = "|";
            string AIComboData = "MY_COMBO";

            PrinterSettings aPrinterSettings = new PrinterSettings();

            foreach (string printer in PrinterSettings.InstalledPrinters)
            {
                // populate the ComboBoxData with this format
                AIComboData += SEP_2 + printer ;

                // code nedded to detect the default printer
                // display default printer as default value in the comboBox control
                aPrinterSettings.PrinterName = printer;
                if (aPrinterSettings.IsDefaultPrinter)
                {
                    session["MY_COMBO"] = aPrinterSettings.PrinterName;
                }
            }

            // Set the Property that will be used as input by the AI PopulateComboBox
            session["AI_COMBOBOX_DATA"] = AIComboData;
            
            return ActionResult.Success;
        }
    }
}
The sample project is attached to this thread, so if you are interested to take a look directly at my project, you are more than welcome to download the ZIP file.

Please note that I've used the PrinterSettings.IsDefaultPrinter Property that requires at least the 4.5 version of the .Net Framework installed on the machine.

Should there be any difficulty you encounter implementing something, please do not hesitate to contact me and I will gladly assist.

Best regards,
Dan
Attachments
Get local and network printers in Combobox.zip
(125.75 KiB) Downloaded 580 times
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Re: Bind list of printers

It worked for me. It would be great help if you can provide me the project which creates the dll.

Thankyou so much for the help.
Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Re: Bind list of printers

I got the solution, Thanks a lot for the help.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Bind list of printers

You're welcome,

Since I already posted the code, all you have to do is to create the custom action project as explain in the Creating a C# custom actions project.

Should there be any difficulty you encounter implementing something, please do not hesitate to contact me and I will gladly assist.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Re: Bind list of printers

Hello Dan,

Thanks for the extended support.

I have followed the steps in the URL you have provided and its working. But the only thing is that the property based folder which was creating was also creating in the browsed directory. To overcome this, as provided in the example i have created the text file but now the text file is creating. I don't want to create any thing with property based folder.

Regards
Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Re: Bind list of printers

Hi Dan,

I have another requirement that needs to set selected printer preferences at install time.

After selecting the printer in combo box and while installing, the printing preferences(such as Image File Resolution etc..) need to be applied to the selected printer without any user intervention.

Thanks for your extended help.
Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Re: Bind list of printers

any help on the above..

Your cooperation is highly appreciated.


Regards
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Bind list of printers

Hi,

I apologize for my delay reply.
When you get the list of the printers, you can also set the properties of the printer. Retrieve the printer properties you are interest in (resolution, etc).

The next step is to get the installer property with the related values as explain in the Retrieving and setting properties article.

If you need any help, please let me know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Sreeram
Posts: 26
Joined: Mon Aug 17, 2015 12:19 pm

Re: Bind list of printers

Hello Dan,

Thanks for your response,

We have two folder dialog's :
1. First Dialog: Bind list of printers in combo box and select one. & click 'Next'
2. Second Dialog: Three text boxes to set three properties (for the selected printer). & click 'Next'

On click next, the three properties given should be set to the selected printer along with 5 other properties which should be set without any user intervention.

Regards
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Bind list of printers

Hi,

To set the printer properties using the values entered by the user, you need to create a custom action. You can search over the internet how to set printer properties programmatically. You will find useful links that you can use as a starting point to develop your custom action.

In order to execute the custom action as a published event on the Next > control, please take a look on the Add custom action without sequence, using a published event as trigger article.

If there is anything else I can help you with, please let me know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”