example usage of FAXCOMEXLib in csharp dotnet

K

kagorami

G'Day,

I am searching for an example of using FAXCOMEXLib in csharp.

The COM interfaces are documented on msdn.microsoft.com however the
examples are for VB and c++.

Following up on a previous topic, FAXCOMEXLib is not in
FAXCOMEXLib.dll, but rather Interop.FAXCOMEXLib.dll

I added a reference to c:\windows\system32\fxscomex.dll to the project,
and it must translate to the above Interop.FAXCOMEXLib.dll

I am a little confused about adding a recipient to a fax document.

I have the fax document object, but the recipients member is
read-only?? So there must be another avenue for adding recipients that
I am yet to discover.

Here is my paltry code (based on code in another newsgroup for
FAXCOMLib)
<code>
using System;
using System.IO;
using System.ComponentModel;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using FAXCOMEXLib;

namespace csFaxComponent
{
public class csFax
{
protected FaxServer ofs = null;
public static void Main()
{
int JobID = 0;
csFax objcsFax = new csFax();
JobID = objcsFax.FaxDocument("C:\\Temp\\any file.txt", "911");
}

private int FaxDocument(String TheFile, string faxnumber)
{
int JobID=0;
FAXCOMEXLib.FaxServer faxsrv = new FAXCOMEXLib.FaxServerClass();
try
{
faxsrv.Connect("");
//Pick up the new changed document and fax it out.
FAXCOMEXLib.FaxDocument faxdoc = new
FAXCOMEXLib.FaxDocumentClass();
faxdoc.Body = TheFile;
//Name the document
faxdoc.DocumentName = "Fax Transmission";
faxdoc.ReceiptAddress = "(e-mail address removed)";
FAXCOMEXLib.FaxRecipients frs = new
FAXCOMEXLib.FaxRecipientsClass();
frs.Add(faxnumber, "John Doe");
faxdoc.Recipients = frs;
faxdoc.ConnectedSubmit(faxsrv);
}
catch
{
}
finally
{
faxsrv.Disconnect();
Marshal.ReleaseComObject(frs);
Marshal.ReleaseComObject(faxdoc);
Marshal.ReleaseComObject(faxsrv);
}
return JobID;
}
}
}
</code>

I was able to send a fax using FAXCOM but I could not seem to get a
good status reply.

I will be faxing out several hundred documents generated by a mail
merge and if there is a problem faxing, then we want to fall back to a
printed/posted document. So the status/jobid is important.

Thanks,

Kim Groves
Accidental
 
A

Alex Feinman [MVP]

There is no need to release the COM wrapper object explicitly - garbage
collector copes with it just fine.

Adding recipients:
strig Phone = "333 555-7676";
FaxRecipient rcpt = faxDoc.Recipients.Add(phone, "Bob Recipient");

Finally, you'll find it very helpful to catch an exception and print it
instead of swallowing. For the period of initial debugging you might even
want to do away with try/catch and let the Studio to break on exception.
This way you know exactly where it happened
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top