≡ Menu




How to Send File to MSMQ Using C#

During the testing of BizTalk application, which read data from MSMQ. I have to write small C# routine, this routine send data to MSMQ.  If you have no knowledge about MSMQ, Please read My Post on this here.
http://www.biztalkhq.com/what-is-msmq-and-how-to-configure-it-on-windows-7/

 

To Send File on MSMQ you have to include the dll System.Messaging in your C# or Vb.net application. To Simplest code is as follow.

 

public void FileToMSMQ(string FilePath, string MsmqName)

{

//FilePath =@”e:test.xml”;

//MsmqName= @".private$testQue";

System.Messaging.MessageQueue _TheQueue = new System.Messaging.MessageQueue(MsmqName);

System.IO.FileStream _FileStream = new System.IO.FileStream(FilePath, System.IO.FileMode.Open);

Message _Message = new Message();

_Message.BodyStream = _FileStream;

_Message.Label = System.IO.Path.GetFileName(FilePath);

_Message.Priority = MessagePriority.Normal;

_TheQueue.Send(_Message);

}
You can down sample code from here

 

 

 

 

Comments on this entry are closed.