Saturday, April 7, 2007

Using Windows Fax Service to Send Fax using C#

somebody Asked this question to me and i thought it would be easy to search rather than to dig

so here it is from

In todays world, while building an application you might run into scenarios where you need to send a Fax from the application. And to a certain extent this is very much required, because I would not want take a print out and go to a fax machine to send a fax. Why cant it be sent from my application?

It is very simple to send a fax using Windows 2000 Fax Service in C#. The application makes use of FaxCom.dll that ships with Windows 2000. This dll is usually located in C:\WINNT\system32 folder. Within the VS.NET IDE, adding a reference to this DLL generates the equivalent Interop.

You can than use the following code to send a fax.

FaxServerClass fs = new FaxServerClass();
fs.Connect("mymachine"); //specifies the machinename
object obj = fs.CreateDocument("myfilename");
FaxDoc fd = (FaxDoc)obj;
fd.FaxNumber = "myfax#";
fd.RecipientName = "Tester";
int i = fd.Send();

Prior to using this, we must make sure to attach the Fax modem, install its drivers and see if the modem is shown within the Device Manager. This same code will also work on Windows 2003 and Windows XP Operating systems.

Now that you have implemented a system which will send a fax. Well what about if you want to receive a fax. Well writing all that would mean serious trouble keeping in mind the small time frame you will have to develop your applicaiton. Well every Fax Server, receives a fax as an image and stores it in a Folder (You can see the destination folder path in the properties). There is also an option to save a copy of the incoming fax to a specific folder. Just set these changes, and write a code which will display the contents of that folder and thats it. You are done with your Fax Integration for your application.