Click here to Skip to main content
13,504,941 members
Click here to Skip to main content
Add your own
alternative version


145 bookmarked
Posted 26 Mar 2003

C# WebCam Service with FTP and Installer

, 31 Mar 2003
Rate this:
Please Sign up or sign in to vote.
C# WebCam Windows Service with FTP upload, Windows Service Installer, and file rotation.


I got tired looking for an app to write a snap shot from my camera to disk; that was free, no ad ware and with no advertising on the image. I found a guy who wrapped the DirectX Library in C# - WHAT A CHAMP! Here's a link to his article. Anyway, he has a full library called DShowNET and I called into that, made a Windows service that always runs when my PC is on. I added a full FTP library that is extended from the work by Jaimon Mathew.


This package comes as a project and a DLL (DShowNET). It has the following files:

  • WebCamService.cs
  • FtpClient.cs
  • Capture.cs
  • WebCamInstaller.cs

Now, using the DShowNET library is a little tricky, and just to get a photo out of the web cam tool some 400 lines of code are required. I extended the Sample Grabber supplied with DShowNET and added the reset event so that the photo could be taken synchronously.

The worst problem was making it stable, but this has been running on my workstation now for 20+ days without a restart. The most important code for stability is in the CloseInterfaces method - note the extensive try/catches - everything must be cleaned up, otherwise strange errors (including blue screens) will be observed.

The FTP library I extended, so I could use it as a full featured FTP client. I have added it to this project so I can upload files to the server.


  • DirectX 8.1
  • .NET Framework
  • Visual Studio .NET (if you plan to edit it of course)
  • A Windows OS that supports Windows Services (2K,XP)
  • Any DirectX supported Video in device (Tuner, Capture, Camera etc...)
  • 5 Minutes of your time


The Installer component is used to install the service with the command:

C:\>installutil.exe D:\projects\webcam\webcamservice\bin\debug\webcamservice.exe

You will also need to edit the config file to reflect your needs:

<add key="path" value="D:\Projects\WebCamService\out\WebCam.jpg"/>
<add key="CaptureCycleSeconds" value="10"/>
<add key="KeepOldImageCount" value="20"/>
<add key="FtpServer" value="???"/>
<add key="FtpUserName" value="???"/>
<add key="FtpPassword" value="???"/>
  • path is where you wish to upload the picture to.
  • CaptureCycleSeconds is how long to wait before taking another photo (add in capture time to 11+ seconds)
  • KeepOldImageCount is to hold the last n photos taken

The rest are pretty explanatory.

Now you cans start and stop the service with the following commands:

net start WebCamService
net stop WebCamService

The service will run in the background, and be started when your machine boots, NOT when you login.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Dan Glass
Australia Australia

You may also be interested in...


Comments and Discussions

GeneralThank you Dan! Pin
Member 105806974-Aug-14 20:01
memberMember 105806974-Aug-14 20:01 
Questionplease help me quickly to send image to my web site quickly Pin
hansalsal23-Feb-11 21:36
memberhansalsal23-Feb-11 21:36 
GeneralLicense Pin
Rocky11388-Jun-10 17:29
memberRocky11388-Jun-10 17:29 
GeneralRe: License Pin
Apple Lam29-Aug-10 16:11
memberApple Lam29-Aug-10 16:11 
GeneralCapture video Pin
dzango23-Mar-10 3:40
memberdzango23-Mar-10 3:40 
GeneralJust works with the first shoot, (looking deeper than other comments) [modified] Pin
joputaidilico31-Mar-08 3:29
memberjoputaidilico31-Mar-08 3:29 
Questionmemory leak? Pin
jgerdes19-Oct-07 11:04
memberjgerdes19-Oct-07 11:04 
GeneralWebcam captures exactly one image, BOMBS on second Pin
Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 12:49
memberPeter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 12:49 
GeneralFtpClient class Runs once then fails Pin
alanmcq13-Mar-07 0:02
memberalanmcq13-Mar-07 0:02 
Question.NET 2.0 work Pin
WarrenHuisman1-Sep-06 13:43
memberWarrenHuisman1-Sep-06 13:43 
GeneralAnother slight modification to the FTPClient Pin
SteveDT12323-Jun-06 6:10
memberSteveDT12323-Jun-06 6:10 
GeneralIntegrate with the Motion Dectection [modified] Pin
syd kahn7-Jun-06 2:43
membersyd kahn7-Jun-06 2:43 
Generalonly run once ? when i restart the service it will run again but once Pin
Mastarezma25-May-06 4:23
memberMastarezma25-May-06 4:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
dakdog32025-May-06 9:10
memberdakdog32025-May-06 9:10 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
Mastarezma25-May-06 13:13
memberMastarezma25-May-06 13:13 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
karande2330-May-06 20:23
memberkarande2330-May-06 20:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
p3kurwud13-Aug-06 8:16
memberp3kurwud13-Aug-06 8:16 
GeneralSet Resolution Pin
doomsday32911-May-06 7:34
memberdoomsday32911-May-06 7:34 
Generalnot able to run the application Pin
ketulvinayshah12-Apr-06 20:38
memberketulvinayshah12-Apr-06 20:38 
GeneralImage Size Pin
mnlux12-Mar-06 15:27
membermnlux12-Mar-06 15:27 
GeneralRe: Image Size Pin
doomsday32911-May-06 7:03
memberdoomsday32911-May-06 7:03 
QuestionHowto change FrameSize? Pin
clemens8120-Jan-06 9:10
memberclemens8120-Jan-06 9:10 
QuestionDamn this so nearly works... Pin
FelixWatts21-Dec-05 7:31
memberFelixWatts21-Dec-05 7:31 
AnswerRe: Damn this so nearly works... Pin
Martijn Stegeman13-Mar-06 4:49
memberMartijn Stegeman13-Mar-06 4:49 
Jokeerror in errorlog .... Pin
codemanloyd2-Dec-05 5:20
membercodemanloyd2-Dec-05 5:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180417.1 | Last Updated 1 Apr 2003
Article Copyright 2003 by Dan Glass
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid