Articles → .NET → Detect Webcam Programmatically In C#
Detect Webcam Programmatically In C#
- First of all download the DLLs from AForge.NET website - ‘http://www.aforgenet.com/framework/downloads.html’
- Once the DLLs are downloaded lets create a windows based application (You can use console based application as well). See the screenshot below for project structure
Click to Enlarge
- Add the reference of following DLLs in the project
- AForge.Video.dll
- AForge.Video.DirectShow
- Add following name space in ‘Form1.cs’
using AForge.Video.DirectShow;
- Add a button on the screen with the caption ‘Detect’ and write the following code on button click event
private FilterInfoCollection devices;
string IsWebCamExists = "NOT EXIST";
private void btnDetectWebcam_Click(object sender, EventArgs e) {
devices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (devices.Count > 0)
IsWebCamExists = "EXIST";
MessageBox.Show(string.Format("Webcam Status: {0}", IsWebCamExists));
}