程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 發送傳真的c#方法

發送傳真的c#方法

編輯:關於C語言
/**//// <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);

   }

  }


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved