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.