How to check if a printer exists in C# and VB.NET

To check if a printer exists in C# and VB.NET you can use the following snippet.

Sample C#

public static bool PrinterExists(string printerName)
{
	if (String.IsNullOrEmpty(printerName)) {  throw new ArgumentNullException("printerName");}
	return PrinterSettings.InstalledPrinters.Cast<string>().Any(name => printerName.ToUpper().Trim() == name.ToUpper().Trim());
}

Sample VB.NET

Public Shared Function PrinterExists(printerName As String) As Boolean
	If String.IsNullOrEmpty(printerName) Then
		Throw New ArgumentNullException("printerName")
	End If
	Return PrinterSettings.InstalledPrinters.Cast(Of String)().Any(Function(name) printerName.ToUpper().Trim() = name.ToUpper().Trim())
End Function

Please Share us:
Please rate this snippet

3 thoughts on “How to check if a printer exists in C# and VB.NET

Leave a Reply