• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

发送传真的c#方法--

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
用FAXCOMLib组件比较简单
楼主可以参考我下面的方法把这个组件安装上:
1.打开控制面板
2.添加和删除程序,选择左边的第三项,也就是那个《增加/删除windwos组件》
3.windows组件向导找到 <传真服务>组件,选中,下一步至到安装完毕,再去system32下就能找到了

4.工程引用该dll,进行开发

代码很多就不说了,下面这个就是

  /// <summary>
  /// ////发送传真的方法,传递三个参数
  /// </summary>
  /// <param name="faxFile"></param>
  /// <param name="faxNumber"></param>
  /// <param name="hostName"></param>
  public void sendFax(string faxFile ,string faxNumber,string hostName)
  {
   
   //writeFile("sendFax faxFile= "+faxFile);
   string sql = "";
   string faxID = "";
   FileInfo f = new FileInfo(faxFile);
   if(f.Exists)
   {
    //FAXCOMLib.FaxServer faxsvr = null;
    FAXCOMLib.FaxDoc faxdoc = null;
    try
    {
     faxsvr = new FAXCOMLib.FaxServer();
     faxdoc = (FAXCOMLib.FaxDoc)faxsvr.CreateDocument(f.FullName);
    }
    catch(Exception ex)
    {
     errorMessage = ex.Message;
     writeFile("create fax server error! " + errorMessage);//Environment.MachineName
    }
    try
    {
     faxsvr.Connect(hostName); // or specify the computer name  Environment.MachineName
    }
    catch (Exception ex )
    {
     errorMessage = ex.Message;
     writeFile("link host "+hostName+ " error! " + errorMessage);
    }

    try
    {
     faxdoc.FileName =f.FullName;
     faxdoc.RecipientTitle = "RecipientTitle";
      faxID = f.Name;//System.DateTime.Now.ToString();/
     //faxdoc.RecipientZip = faxID;
     //writeFile("sendFax faxFile= "+faxFile + "; f.fullname=" + faxdoc.FileName);
//     //-----------------------------------------------------////////
     faxdoc.RecipientAddress = "RecipientAddress";
     faxdoc.RecipientCompany = "RecipientCompany";
     faxdoc.RecipientCountry = "RecipientCountry";
     faxdoc.RecipientDepartment = "RecipientDepartment";
     faxdoc.RecipientHomePhone = "RecipientHomePhone";
     faxdoc.RecipientName = faxID;////////////传真id号
     faxdoc.RecipientOffice = "RecipientOffice";
     faxdoc.RecipientOfficePhone = "RecipientOfficePhone";
     //faxdoc.SendCoverpage = 0;
     faxdoc.SenderAddress = "SenderAddress";
     faxdoc.SenderCompany = "SenderCompany";
     faxdoc.SenderDepartment = "SenderDepartment";
     faxdoc.SenderFax = "SenderFax";
     faxdoc.SenderHomePhone = "SenderHomePhone";
     faxdoc.SenderOfficePhone = "SenderOfficePhone";
     faxdoc.SenderTitle = "SenderTitle";
     //faxdoc.ServerCoverpage = 1;
     faxdoc.CoverpageName = "CoverpageName";
     faxdoc.CoverpageNote = "CoverpageNote";
     faxdoc.CoverpageSubject = "CoverpageSubject";
//     //------------------------------------------------------//////////
     faxdoc.FaxNumber =faxNumber;// Specify the Fax Number;
     //writeFile("f.FullName= "+f.FullName + "; faxdoc.FileName=" + faxdoc.FileName);
     intsend = faxdoc.Send();
     writeFile("faxdoc.tsid= " + faxdoc.SendCoverpage + "; GetHashCode" + faxdoc.GetHashCode() + "; FileName:" + faxdoc.FileName  );
     //System.Threading.Thread.Sleep(2000);
     //faxsvr.Disconnect();
     writeFile("send  successfully["+intsend+"]  " + f.FullName + "  " +"(faxNumber: " +faxNumber +";hostName: " +hostName+ ")");
                    sign = 1;
    }
    catch ( Exception ex )
    {
     errorMessage = ex.Message;
     writeFile("send   error["+intsend+"]  "       +f.FullName+"     "+errorMessage + "(faxNumber: " +faxNumber +";hostName: " +hostName+")");
     sign =0;
     //System.Threading.Thread.Sleep(5000);
    }
    
   }
   else
   {
    sign =0;
    errorMessage = "error:"+faxFile +"  not exist !";
    writeFile(errorMessage);
   }
   if( sign ==0)
   {
    sql = "UPDATE job_log SET result_message = 'error:"+errorMessage.Replace("'","''")+"',log_title='"+faxID+"' " ;
    sql += " Where sql like '%"+f.Name +"' and event_type ='FAX'";
    sqlUpdate(sql);

   }
   else if (sign ==1)
   {
    sql = "UPDATE job_log SET result_message = 'successfully',log_title ='"+faxID+"'" ;
    sql += " Where sql like '%"+f.Name +"' and event_type ='FAX'";
    sqlUpdate(sql);

   }

  }

 

        /// <summary>
    /// 发传真
    /// </summary>
    /// <param name="DocumentName">文件名</param>
    /// <param name="FileName">发送的文件路径</param>
    /// <param name="RecipientName">收件人姓名</param>
    /// <param name="FaxNumber">传真号</param>
    /// <returns></returns>
    public bool SendFax(string DocumentName,string FileName, string RecipientName, string FaxNumber)
    {
        bool bo = false;
        if (FaxNumber != "")
        {
            try
            {
                FAXCOMLib.FaxServer faxServer = new FAXCOMLib.FaxServerClass();
                faxServer.Connect(Environment.MachineName);//获取当前服务器名
                FAXCOMLib.FaxDoc faxDoc = (FAXCOMLib.FaxDoc)faxServer.CreateDocument(FileName);
                faxDoc.RecipientName = RecipientName;//收件人姓名或者公司名
                faxDoc.FaxNumber = FaxNumber;//收件人传真号码
                faxDoc.DisplayName = DocumentName;//文档名
                int Response = faxDoc.Send();//程序到fax server的流水號
                faxServer.Disconnect();
                bo = true;
            }
            catch (Exception Ex)
            {
                bo = false;
            }
        }
        return bo;
    }
    //为了在工程中引用faxcom 1.0 Type Library,必须首先安装Windows Component 中的Fax services。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#多线程同步发布时间:2022-07-18
下一篇:
asp.net网页中调用c#写的dll文件发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap