首页 > 代码库 > FAXCOM和FXSCOMEX 传真编程
FAXCOM和FXSCOMEX 传真编程
需要引用的dl,如下信息,早起使用的是FXSCOM.DLL,现在微软提供了相应的扩展,其程序集为,FXSCOMEX.dll
FXSCOMEX.dll 提供跟加健全的方法,可以说所有关于传真的操作都在这个dll中。
以下是传真中使用的主要方法:
- 首先定义一个封装传真人相关信息的Bean
1 //定义传真需要封装的传真人相关的信息 2 public class FaxPeopleBean 3 { 4 public string Name; 5 public string FaxNumber; 6 public string Company; 7 8 public DateTime ScheduleTime; 9 10 public FaxPeopleBean()11 {12 ScheduleTime = QLOAParams.DtSqlDbMinValue;13 }14 }
2. 发送传真的方法
1 public object sendFaxBatchDoc(FaxPeopleBean recipient, FaxPeopleBean sender, List<string> docList) 2 { 3 bool isConnected=false; 4 FaxServer objFaxServer=null; 5 try 6 { 7 objFaxServer = new FaxServer(); 8 FaxDocument objFaxDocument = new FaxDocument(); 9 Object jobIds;//每次发送后,都会返回一个传真作业id,用于监控此传真的发送情况10 //Connect to the fax server11 objFaxServer.Connect(""); //""代表连接到本地机器服务,也可以使用其它网络传真服务器12 isConnected = true;13 SetOutgoingQueue(objFaxServer);14 objFaxDocument.Sender.Name = sender.Name;15 objFaxDocument.Sender.Company = sender.Company;16 objFaxDocument.Sender.FaxNumber = sender.FaxNumber;17 if (sender.ScheduleTime != QLOAParams.DtSqlDbMinValue)18 {19 // Specify that the fax is to be sent at a particular time20 objFaxDocument.ScheduleType = FAXCOMEXLib.FAX_SCHEDULE_TYPE_ENUM.fstSPECIFIC_TIME;21 //CDate converts the time to the Date data type22 objFaxDocument.ScheduleTime = sender.ScheduleTime;23 }24 25 //Set the fax priority26 objFaxDocument.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH;27 // ‘Add the recipient28 objFaxDocument.Recipients.Add(recipient.FaxNumber, recipient.Name);29 string[] files = docList.ToArray();30 object bodys = files;31 objFaxDocument.Bodies = bodys;32 int result = objFaxDocument.ConnectedSubmit2(objFaxServer, out jobIds);33 return jobIds;34 }35 finally36 {37 if (isConnected && objFaxServer!=null)38 {39 objFaxServer.Disconnect();40 } 41 }42 }
3. 用于设置传真的一些属性,必须连接过后才可以设置
public void SetOutgoingQueue(FaxServer objFaxServer) { FaxOutgoingQueue objFaxOutgoingQueue; //‘Get the outgoing queue object objFaxOutgoingQueue = objFaxServer.Folders.OutgoingQueue; //‘Refresh the queue object objFaxOutgoingQueue.Refresh(); objFaxOutgoingQueue.Retries = 10; //重试10次后不再发生 objFaxOutgoingQueue.RetryDelay = 1; //The Branding property is a Boolean value that indicates whether the fax service generates a brand (banner) //at the top of outgoing fax transmissions. A brand contains transmission-related information, such as the transmitting //station identifier, date, time, and page count. objFaxOutgoingQueue.Branding = true; }
4. 取消某个传真的发送
public void CancelOutgoingQueue(string faxJobid) { FaxServer objFaxServer = new FaxServer(); FaxOutgoingQueue objFaxOutgoingQueue; FaxOutgoingJob objFaxOutgoingJob; //‘Connect to the fax server objFaxServer.Connect(""); //‘Get the outgoing queue object objFaxOutgoingQueue = objFaxServer.Folders.OutgoingQueue; //‘Refresh the queue object objFaxOutgoingQueue.Refresh(); try { objFaxOutgoingJob = (FaxOutgoingJob)objFaxOutgoingQueue.GetJob(faxJobid); //找不到时会发生异常 objFaxOutgoingJob.Cancel(); } catch { } objFaxServer.Disconnect(); }
5. 需要对传真发送情况进行监控
FAXCOMEXLib.FaxServer _faxServer= new FaxServer(); _faxServer.Connect(""); _faxServer.OnOutgoingJobChanged +=FaxServer_OnOutgoingJobChanged;
_faxServer.ListenToServerEvents( FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED | FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE;
6. 监控的方法在这里
public void FaxServer_OnOutgoingJobChanged(FAXCOMEXLib.IFaxServer pFaxServer, string bstrJobId, FAXCOMEXLib.IFaxJobStatus pJobStatus) { //根据pJobStatus 枚举可以实时的获取,传真的发生情况,具体的操作代码可以写作这里
}
FAXCOM和FXSCOMEX 传真编程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。