Sending a file with MSMQ

  • Thread starter Thread starter Guest
  • Start date Start date
Rami,
Do you want to send the contents of the file or do you want to send the file
name?

To send the contents of a file, the "easiest" way is to set the BodyStream
property of the message.

Dim theQueue As System.Messaging.MessageQueue

Dim thePath As String = "c:\myfile.txt"
Dim theStream As New System.IO.FileStream(thePath, IO.FileMode.Open)
Dim theMessage As New Message

theMessage.BodyStream = theStream
theMessage.Label = System.IO.Path.GetFileName(thePath)
theMessage.Priority = MessagePriority.Normal
theQueue.Send(theMessage)

The send the file name, you can simply use:

Dim theMessage As New Message(thePath)
theMessage.Label = System.IO.Path.GetFileName(thePath)
theMessage.Priority = MessagePriority.Normal
theQueue.Send(theMessage)

Hope this helps
Jay
 
Back
Top