How to select scanner by its name ?

This KB is for Dynamic .NET TWAIN v7.* + only.
Dynamic .NET TWAIN offers a method named SelectSourceByIndex which allows you to select the index of the source in SourceNameItems property as the current source.

However, in some cases, you may want to select a source by source name. There isn’t such a method, but that can be achieved by a few lines of code.

Following is the sample code:

            for (short i = 0; i < m_TwainManager.SourceCount; i++)
            {
                string PSourceName = "7500"; //"7500" is part of the source name   
                if (m_TwainManager.SourceNameItems(i).IndexOf(PSourceName) != -1)
                {
                    m_TwainManager.SelectSourceByIndex(i);
                    break;
                }         
            }

In the sample, we use a scanner named HP Scanjet Enterprise 7500. So the PSourceName can be “7500”.

Please change the PSourceName accordingly. In order to select the right source as you wanted, please make sure that the PSourceName is unique to all the source.

Is this page helpful?

Leave a Reply

Your email address will not be published.