Jan 262009
 

A friend from Chile asked about how to extract a filename from a message, after going back and forth, I sent him this code that I use in my EDI logger

private static string extractFileName(IBaseMessage inmsg) { string adapterType = (string)inmsg.Context.Read("InboundTransportType", "http://schemas.microsoft.com/BizTalk/2003/system-properties"); string ReceivedFileName = ""; //make sure it is an adapter that we can get a file name from if (adapterType == "FILE" || adapterType == "FTP") { if (adapterType == "FILE") { ReceivedFileName = (string)inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties"); } else if (adapterType == "FTP") { ReceivedFileName = (string)inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/ftp-properties"); } } return Path.GetFileName(ReceivedFileName); }

Since he said he could not find anything out there on how to do it, I figured I would post it for everyone’s edification.

  • Duilio Raffo

    Thanks Eric! Great post. Ellegant and exact. Just one warning (for those like me that are writing a custom adapter with Receive/Send functionality): remember to write the “ReceivedFileName” property in the context of the received message (in your ReceiverAdapter code), otherwise the property won’t exist…