c# 发送传真的方法

来源:互联网 发布:union intersect sql 编辑:程序博客网 时间:2024/05/17 02:10

 

private void SendFax()
  {
   
   string hostName = Dns.GetHostName();
   string dir =System.Configuration.ConfigurationSettings.AppSettings["FaxDocPath"].ToString();
   string faxFile =@"//"+hostName+@"/"+dir+@"/"+Session["FileGuid"];
   string errorMessage;
   int intsend=0;
   string faxID = "";
   int sign;

   string faxNumber = "";
   for(int i=0;i<this.lstSelectCompany.Items.Count;i++)
   {
    faxNumber = this.lstSelectCompany.Items[i].Value;

    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;
     }
     try
     {
      faxsvr.Connect(hostName);    // or specify the computer name  Environment.MachineName
     }
     catch (Exception ex )
     {
      errorMessage = ex.Message;
     }
     try
     {
      faxdoc.FileName =f.FullName;
      faxdoc.RecipientTitle = "RecipientTitle";
      faxID = f.Name;            //System.DateTime.Now.ToString();/
      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.SenderAddress = "SenderAddress";
      faxdoc.SenderCompany = "SenderCompany";
      faxdoc.SenderDepartment = "SenderDepartment";
      faxdoc.SenderFax = "SenderFax";
      faxdoc.SenderHomePhone = "SenderHomePhone";
      faxdoc.SenderOfficePhone = "SenderOfficePhone";
      faxdoc.SenderTitle = "SenderTitle";
      faxdoc.CoverpageName = "CoverpageName";
      faxdoc.CoverpageNote = "CoverpageNote";
      faxdoc.CoverpageSubject = "CoverpageSubject";
      
      faxdoc.FaxNumber =faxNumber;       // Specify the Fax Number;
      intsend = faxdoc.Send();
      sign = 1;
     }
     catch ( Exception ex )
     {
      errorMessage = ex.Message;
      WriteAppLog(errorMessage);
      throw new Exception(errorMessage);
     }
    }
   }
  }

原创粉丝点击