How to get the source file name in a pipeline component

In previous entries I have shown how to access Pipeline Context items.  There are a number of 'built in' promoted properties that provide important information.  There are different items for the receive and send pipelines.

 

The 14 receive pipeline items are (including the associated namespace):

 1.  ReceivedFileName (https://schemas.microsoft.com/BizTalk/2003/file-properties)

 2.  InboundTransportLocation (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 3.  InterchangeID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 4.  ReceivePortID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 5.  ReceivePortName (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 6.  WasSolicitResponse (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 7.  AuthenticationRequiredOnReceivePort (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 8.  InboundTransportType (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 9.  LRPMsgBodyTracking (https://schemas.microsoft.com/BizTalk/2003/system-properties)

10. MessageExchangePattern (https://schemas.microsoft.com/BizTalk/2003/system-properties)

11. PortName (https://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

12. ReceivePipelineID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

13. MessageType (https://schemas.microsoft.com/BizTalk/2003/system-properties)

14. SchemaStrongName (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 

While the 31 send pipeline items are

1.  CopyMode (https://schemas.microsoft.com/BizTalk/2003/file-properties)

2.  LTPMsgBodyTracking (https://schemas.microsoft.com/BizTalk/2003/system-properties)

3.  ReceivedFileName (https://schemas.microsoft.com/BizTalk/2003/file-properties)

4.  SPID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

5.  ActualRetryCount (https://schemas.microsoft.com/BizTalk/2003/system-properties)

6.  FileName (https://schemas.microsoft.com/BizTalk/2003/file-properties)

7.  PartyName (https://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

8.  ReceivePortName (https://schemas.microsoft.com/BizTalk/2003/system-properties)

9.  WasSolicitResponse (https://schemas.microsoft.com/BizTalk/2003/system-properties)

10. AllowCacheOnWrite (https://schemas.microsoft.com/BizTalk/2003/file-properties)

11. RetryInterval (https://schemas.microsoft.com/BizTalk/2003/system-properties)

12. OutboundTransportCLSID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

13. SPName (https://schemas.microsoft.com/BizTalk/2003/system-properties)

14. InboundTransportLocation (https://schemas.microsoft.com/BizTalk/2003/system-properties)

15. InterchangeID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

16. ReceivePortID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

17. SPTransportID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

18. TransmitPipelineID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

19. AuthenticationRequiredOnReceivePort (https://schemas.microsoft.com/BizTalk/2003/system-properties)

20. InboundTransportType (https://schemas.microsoft.com/BizTalk/2003/system-properties)

21. LRPMsgBodyTracking (https://schemas.microsoft.com/BizTalk/2003/system-properties)

22. MessageExchangePattern (https://schemas.microsoft.com/BizTalk/2003/system-properties)

23. OutboundTransportLocation (https://schemas.microsoft.com/BizTalk/2003/system-properties)

24. PortName (https://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

25. ReceivePipelineID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

26. SourcePartyID (https://schemas.microsoft.com/BizTalk/2003/system-properties)

27. MessageType (https://schemas.microsoft.com/BizTalk/2003/system-properties)

28. OutboundTransportType (https://schemas.microsoft.com/BizTalk/2003/system-properties)

29. PartNames (https://schemas.microsoft.com/BizTalk/2003/messageagent-properties)

30. RetryCount (https://schemas.microsoft.com/BizTalk/2003/system-properties)

31. SchemaStrongName (https://schemas.microsoft.com/BizTalk/2003/system-properties)

 

 

To get access to these properties you need to get access to the context object.  The following method shell shows how we can do that.

 

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)

{

IBaseMessageContext context = pInMsg.Context;

 

Place code here to work with the context object (look at this blog entry to get more details on this method)

.

.

.

}

 

Now that we have a method to gain access to the context, what if we want to get access to the internal promoted properties?  We can iterate through all of the default promoted properties by using the context.ReadAt method (which produces the list of the items above).  This method takes an index and returns, through 2 out parameters, the name and namespace of the properties. 

 

We can also use the context.Read method to access the value of each of these promoted properties.  The Read method returns an object type containing the value of the promoted property when passing in the name and namespace of the property.

 

So, to retrieve the source file name we would use this following line of code:

 

string srcFileName = context.Read("ReceivedFileName", "https://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();