Export (0) Print
Expand All

MessageQueue.Path Property

Gets or sets the queue's path. Setting the Path causes the MessageQueue to point to a new queue.

Namespace: System.Messaging
Assembly: System.Messaging (in system.messaging.dll)

[TypeConverterAttribute("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 
public string Path { get; set; }
/** @property */
public String get_Path ()

/** @property */
public void set_Path (String value)

public function get Path () : String

public function set Path (value : String)

Not applicable.

Property Value

The queue that is referenced by the MessageQueue. The default depends on which MessageQueue constructor you use; it is either a null reference (Nothing in Visual Basic) or is specified by the constructor's path parameter.

Exception typeCondition

ArgumentException

The path is not valid, possibly because the syntax is not valid.

The syntax for the Path property depends on the type of queue it points to, as shown in the following table.

Queue type

Syntax

Public queue

MachineName\QueueName

Private queue

MachineName\Private$\QueueName

Journal queue

MachineName\QueueName\Journal$

Machine journal queue

MachineName\Journal$

Machine dead-letter queue

MachineName\Deadletter$

Machine transactional dead-letter queue

MachineName\XactDeadletter$

Use "." to represent the local computer.

The MachineName, Path, and QueueName properties are related. Changing the MachineName property causes the Path property to change. It is built from the new MachineName and the QueueName. Changing the Path (for example, to use the format name syntax) resets the MachineName and QueueName properties to refer to the new queue.

Alternatively, you can use the FormatName or Label to describe the queue path, as shown in the following table.

Reference

Syntax

Example

Format name

FormatName: [ format name ]

FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112

Label

Label: [ label ]

Label: TheLabel

If you use the label syntax for the Path property when you send the message, an exception will be thrown if the Label is not unique.

To work offline, you must use the format name syntax, rather than the friendly name syntax in the first table. Otherwise, an exception is thrown because the primary domain controller (on which Active Directory resides) is not available to resolve the path to the format name.

Setting a new path closes the message queue and releases all handles.

The following table shows whether this property is available in various Workgroup modes.

Workgroup mode

Available

Local computer

Yes

Local computer and direct format name

Yes

Remote computer

Yes

Remote computer and direct format name

Yes

NoteNote:

In workgroup mode you can only use private queues. You specify the path using the private queue syntax MachineName\Private$\QueueName.

Windows Mobile 2003 for Pocket PC, Windows Mobile 2003 for Smartphone, Windows CE Platform Note: Because the Active Directory is not supported on devices, the .NET Compact Framework cannot determine if a remote queue is transactional. To send a message to a remote transaction queue, append ;XACTONLY to Path property. For more information, see MSMQ in the .NET Compact Framework.

The following code example creates new MessageQueue objects using various path name syntax types. In each case, it sends a message to the queue whose path is defined in the constructor.

using System;
using System.Messaging;

namespace MyProject
{
	/// <summary>
	/// Provides a container class for the example.
	/// </summary>
	public class MyNewQueue
	{

		//**************************************************
		// Provides an entry point into the application.
		//		 
		// This example demonstrates several ways to set
		// a queue's path.
		//**************************************************

		public static void Main()
		{
			// Create a new instance of the class.
			MyNewQueue myNewQueue = new MyNewQueue();

			myNewQueue.SendPublic();
			myNewQueue.SendPrivate();
			myNewQueue.SendByLabel();
			myNewQueue.SendByFormatName();
			myNewQueue.MonitorComputerJournal();
			myNewQueue.MonitorQueueJournal();
			myNewQueue.MonitorDeadLetter();
			myNewQueue.MonitorTransactionalDeadLetter();

			return;
		}
		
		// References public queues.
		public void SendPublic()
		{
			MessageQueue myQueue = new MessageQueue(".\\myQueue");
			myQueue.Send("Public queue by path name.");

			return;
		}

		// References private queues.
		public void SendPrivate()
		{
			MessageQueue myQueue = new 
				MessageQueue(".\\Private$\\myQueue");
			myQueue.Send("Private queue by path name.");

			return;
		}

		// References queues by label.
		public void SendByLabel()
		{
			MessageQueue myQueue = new MessageQueue("Label:TheLabel");
			myQueue.Send("Queue by label.");

			return;
		}

		// References queues by format name.
		public void SendByFormatName()
		{
			MessageQueue myQueue = new 
				MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + 
				"-935C-845C2AFF7112");
			myQueue.Send("Queue by format name.");

			return;
		}

		// References computer journal queues.
		public void MonitorComputerJournal()
		{
			MessageQueue computerJournal = new 
				MessageQueue(".\\Journal$");
			while(true)
			{
				Message journalMessage = computerJournal.Receive();
				// Process the journal message.
			}
		}

		// References queue journal queues.
		public void MonitorQueueJournal()
		{
			MessageQueue queueJournal = new 
				MessageQueue(".\\myQueue\\Journal$");
			while(true)
			{
				Message journalMessage = queueJournal.Receive();
				// Process the journal message.
			}
		}
		
		// References dead-letter queues.
		public void MonitorDeadLetter()
		{
			MessageQueue deadLetter = new 
				MessageQueue(".\\DeadLetter$");
			while(true)
			{
				Message deadMessage = deadLetter.Receive();
				// Process the dead-letter message.
			}
		}

		// References transactional dead-letter queues.
		public void MonitorTransactionalDeadLetter()
		{
			MessageQueue TxDeadLetter = new 
				MessageQueue(".\\XactDeadLetter$");
			while(true)
			{
				Message txDeadLetter = TxDeadLetter.Receive();
				// Process the transactional dead-letter message.
			}
		}

	}
}

package MyProject;

import System.*;
import System.Messaging.*;

/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
    //**************************************************
    // Provides an entry point into the application.
    //         
    // This example demonstrates several ways to set
    // a queue's path.
    //**************************************************
    public static void main(String[] args)
    {
        // Create a new instance of the class.
        MyNewQueue myNewQueue = new MyNewQueue();

        myNewQueue.SendPublic();
        myNewQueue.SendPrivate();
        myNewQueue.SendByLabel();
        myNewQueue.SendByFormatName();
        myNewQueue.MonitorComputerJournal();
        myNewQueue.MonitorQueueJournal();
        myNewQueue.MonitorDeadLetter();
        myNewQueue.MonitorTransactionalDeadLetter();

        return;
    } //main

    // References public queues.
    public void SendPublic()
    {
        MessageQueue myQueue = new MessageQueue(".\\myQueue");
        myQueue.Send("Public queue by path name.");
        return;
    } //SendPublic

    // References private queues.
    public void SendPrivate()
    {
        MessageQueue myQueue = new MessageQueue(".\\Private$\\myQueue");
        myQueue.Send("Private queue by path name.");
        return;
    } //SendPrivate

    // References queues by label.
    public void SendByLabel()
    {
        MessageQueue myQueue = new MessageQueue("Label:TheLabel");
        myQueue.Send("Queue by label.");
        return;
    } //SendByLabel

    // References queues by format name.
    public void SendByFormatName()
    {
        MessageQueue myQueue =
            new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4"
            + "-935C-845C2AFF7112");
        myQueue.Send("Queue by format name.");
        return;
    } //SendByFormatName

    // References computer journal queues.
    public void MonitorComputerJournal()
    {
        MessageQueue computerJournal = new MessageQueue(".\\Journal$");
        while (true) {
            Message journalMessage = computerJournal.Receive();
            // Process the journal message.
        }
    } //MonitorComputerJournal

    // References queue journal queues.
    public void MonitorQueueJournal()
    {
        MessageQueue queueJournal = new MessageQueue(".\\myQueue\\Journal$");
        while (true) {
            Message journalMessage = queueJournal.Receive();
            // Process the journal message.
        }
    } //MonitorQueueJournal

    // References dead-letter queues.
    public void MonitorDeadLetter()
    {
        MessageQueue deadLetter = new MessageQueue(".\\DeadLetter$");
        while (true) {
            Message deadMessage = deadLetter.Receive();
            // Process the dead-letter message.
        }
    } //MonitorDeadLetter

    // References transactional dead-letter queues.
    public void MonitorTransactionalDeadLetter()
    {
        MessageQueue objTxDeadLetter = new MessageQueue(".\\XactDeadLetter$");
        while (true) {
            Message txDeadLetter = objTxDeadLetter.Receive();
            // Process the transactional dead-letter message.
        }
    } //MonitorTransactionalDeadLetter
} //MyNewQueue

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft