Saturday, August 7, 2010

Sending Fax from your application

On windows Server 2003 have capabilities act as fax server. so many client can be sending the document with fax service via this server. but on windows XP professional also have fax service like on server 2003 but not richeest functional like on server 2003. on windows XP You must active this service via add and remove windows component on control panel.
Like on microsoft office , The app have feature for sending document via email or fax service. on this post we can add that capabilities into .net project.  The project use windows xp proffesional for replace windows 2003 server.

faxing-300x266

 

Before started this project we must make sure fax service installed on Computer. because the project need component from that service. on the work sheet visual studio 2008 add the reference FAXCOMEXlib.dll into project. The source code like below

  1. Public Class Form1

  2. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

  3. With cd

  4. .ShowDialog()

  5. TextBox5.Text = cd.FileName

  6. End With

  7. End Sub

  8. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  9. TextBox1.Text = My.Computer.Name.ToString

  10. End Sub

  11. Private Sub sending()

  12. Dim objFaxDocument As New FAXCOMEXLib.FaxDocument

  13. Dim objFaxServer As New FAXCOMEXLib.FaxServer

  14. Dim objSender As FAXCOMEXLib.FaxSender

  15. Dim jobid As Int32

  16. If TextBox1.Text = "" Or TextBox2.Text = "" Then

  17. MsgBox("Please input server name and destination number !", MsgBoxStyle.Critical, "Faxing")

  18. Exit Sub

  19. End If

  20. Try

  21. objFaxServer.Connect("")

  22. objFaxDocument.Body = TextBox5.Text

  23. objFaxDocument.DocumentName = "Reliez "

  24. objFaxDocument.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH

  25. objFaxDocument.Recipients.Add(TextBox2.Text, TextBox3.Text)

  26. objFaxDocument.Sender.Company = "Reliez "

  27. objFaxDocument.Sender.StreetAddress = "Http:" & "//" & "reliez.net"

  28. objFaxDocument.Sender.SaveDefaultSender()

  29. objFaxDocument.ConnectedSubmit(objFaxServer)

  30. System.Threading.Thread.Sleep(5000)

  31. objFaxServer.Disconnect()

  32. Me.Close()

  33. Catch ex As Exception

  34. MsgBox(ex.ToString)

  35. 'MsgBox("Fail to Send Document !", MsgBoxStyle.Critical, "Fax")

  36. End Try

  37. End Sub

  38. End Class

Download complete source code click this link

Tag Technorati: {grup-tag},