Click here to Skip to main content
15,305,480 members
Articles / DevOps
Posted 27 Oct 2015

Tagged as


9 bookmarked

Work with Fax [Using FAXCOMEXLib]

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
27 Oct 2015CPOL4 min read
This article is about how to receive fax in windows


In this article i'm talking about how to be aware when a fax recieve and take the fax, in this article we are using FAXCOMEXLib and we won't go through advance stuff as i'm unaware of many things, but as i needed to know this much and nobody shared any thing about it, i though it gonna be useful for Beginners. I also like to here your idea to make the article work better and more internally.


It was sometimes ago, my manager asked me for ability to receive fax, and i was wonder, what fax? so i start searching, i find nothing much, just several paid library, and a Fax4J library, first i though of converting the lib for .Net but it was failur as it only provided sending features. so, i just follow something about FAXCOMLib and i find several different question answers. they all were alike, and the source was MSDN, but it was disappointing at it didn't had that much of information. BTW, i follow those things and rich nowhere far but here. and i'm goin' to share this.

Where to find the Library

First thing you gonna need to work with this library is the library itself. so you do need to provide it somehow. for that you need to install one of windows feature that is named "Fax Server Tools", in non server windows it may have a different name.

Image 1

After installing this feature, you can search for the dll inside your VS, So go to References Node of your solution explorer, and then right click on it, and choose "Add Reference...", next move to COM section. and choose the "faxcom 1.0 Type Library".

Image 2

Now you have the reference you need.

Using the code

Well as you are done most of the things you should do, i'm wonder how i should talk about the code in here, on a way that you don't say "This is it?"

So here we start...

First you need to import the "FAXCOMEXLib" namespace.

Then you gonna need to create an instance of the FaxServerClass too.
The FaxServerClass is a class that communicate with the windows Fax Service. and receive fax events. Since You may be over a network and your fax server be on a different machine, you need to tell the class which machine it need to connect to. so You give it a computer name, which you can find your on on the propertise of your computer, can be found by right clicking over MyComputer, or ThisPC on windows server, and choose "Propertiese".

Image 3

Now, you have both the class instance and the name of the computer who running the Fax Service on. the only this is left to perform the first step, is to connect to that PC, so you will call the Connect Method.

So it gonna be something like this:

public class Fax
    private readonly FaxServerClass faxSrv;
    public Fax()
        faxSrv = new FaxServerClass();

        var serverName = "WIN-0640S5M4APO";


Now you are connected to the service, but what now? you need to be notified and even then you need to do your own stuffs. So you need to define and register for the events.

public Fax()
    faxSrv.OnOutgoingJobChanged += faxSrv_OnOutgoingJobChanged;
    faxSrv.OnOutgoingJobAdded += faxSrv_OnOutgoingJobAdded;
    faxSrv.OnOutgoingJobRemoved += faxSrv_OnOutgoingJobRemoved;

    faxSrv.OnIncomingJobAdded += faxSrv_OnIncomingJobAdded;
    faxSrv.OnIncomingJobChanged += faxSrv_OnIncomingJobChanged;
    faxSrv.OnIncomingJobRemoved += faxSrv_OnIncomingJobRemoved;
private void faxSrv_OnIncomingJobRemoved(FaxServer pfaxserver, string bstrjobid)
    //Your Codes

private void faxSrv_OnIncomingJobChanged(FaxServer pfaxserver, string bstrjobid, FaxJobStatus pjobstatus)
    //Your Codes

private void faxSrv_OnIncomingJobAdded(FaxServer pfaxserver, string bstrjobid)
    //Your Codes

private void faxSrv_OnOutgoingJobRemoved(FaxServer pfaxserver, string bstrjobid)
    //Your Codes

private void faxSrv_OnOutgoingJobAdded(FaxServer pfaxserver, string bstrjobid)
    //Your Codes

private void faxSrv_OnOutgoingJobChanged(FaxServer pfaxserver, string bstrjobid, FaxJobStatus pjobstatus)
    //Your Codes

As you have seen a lot of times, this is how we register for event <instance>.<event> += <Your method>;, and you implement your method, after that, every time an event occure it will go through your code and do what you need to be done, but in this library, it alone won't do any thing... you need to filter the events you need, and tell the machin which events to filter, the following are some of important filter we goona need.

/* This one activates:
   - OnOutgoingJobChanged
   - OnOutgoingJobAdded
   - OnOutgoingJobRemoved*/
/* And this one activates:
   - OnIncomingJobChanged
   - OnIncomingJobAdded
   - OnIncomingJobRemoved*/

So we need to tell the class to filter these event for us, and listen to them, here's how we do this:

public Fax()

With this one line, your class start to work, and as we right these all on constructor, it just begin it's work once you new it. but, before these events trigger we need to answer the calls, so you need to tell your Fax Service to do this for you. search for Fax Service Manager on your server, it may have different names on different OS, or may only be exist on a server machins, i'm not sure of this.

Image 4

Well after you run this application, you need to find your modem node, the one is connected to the line, and then tell him to answer calls automatically.

Image 5

And now every thing is ready, you can put some break points inside your methods, and catch the event that occure...

I my self used the OnIncomingJobRemoved to be notified after receiving a fax, and do some operation on the resulting data... here's what i do:

private void faxSrv_OnIncomingJobRemoved(FaxServer pfaxserver, string bstrjobid)
    Console.WriteLine("IN - Job ID: " + bstrjobid + " Job Removed from Fax Queue");
    var baseDir = pfaxserver.Configuration.ArchiveLocation;
    var inbox = baseDir + "\\Inbox";
    string[] files = Directory.GetFiles(inbox);

    //Method That search for current file inside the file list...
    Func<string[], string, string> getFilePath =
        (fileList, searchId) => (
            from file in fileList
            let fileName = Path.GetFileNameWithoutExtension(file)
            let dollarIndex = fileName.IndexOf('$')
            where dollarIndex != -1
            where Path.GetFileNameWithoutExtension(file)?.Substring(dollarIndex + 1) == searchId
            select file

    string filePath = getFilePath(files, bstrjobid);

In the last line of code you have the file that is received, which also is kept inside archive folder of the place that has been set for the fax service, you can process it... .

Be aware that i used some of C# 5 or 6 feature in here. like x?.y() mean if(x!=null) x.y()

Thank you for reading,
And if you know something, please tell my to let people have better exprience using this library.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hassan Faghihi
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

Comments and Discussions

QuestionMicrosoft Fax and Scan Problem Pin
Member 1268734520-Jul-18 7:25
MemberMember 1268734520-Jul-18 7:25 
Questioni need your help Pin
Milad19899-May-17 2:25
MemberMilad19899-May-17 2:25 
AnswerRe: i need your help Pin
Hassan Faghihi17-Jan-18 23:10
MemberHassan Faghihi17-Jan-18 23:10 
QuestionVery much usefull. Pin
Member 1197748327-Feb-17 18:02
MemberMember 1197748327-Feb-17 18:02 
AnswerRe: Very much usefull. Pin
Hassan Faghihi17-Jan-18 23:04
MemberHassan Faghihi17-Jan-18 23:04 
Questionwhat hardware is required? Pin
Sara NA9-Jan-16 21:14
MemberSara NA9-Jan-16 21:14 
AnswerRe: what hardware is required? Pin
Hassan Faghihi18-Jan-16 1:44
MemberHassan Faghihi18-Jan-16 1:44 
GeneralMy Vote of 5 Pin
aarif moh shaikh28-Oct-15 18:47
professionalaarif moh shaikh28-Oct-15 18:47 
GeneralRe: My Vote of 5 Pin
Hassan Faghihi28-Oct-15 22:27
MemberHassan Faghihi28-Oct-15 22:27 
GeneralRe: My Vote of 5 Pin
aarif moh shaikh2-Nov-15 18:28
professionalaarif moh shaikh2-Nov-15 18:28 

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.