The underlying connection was closed: The connection was closed unexpectedly.

I’m sure there are numerous reasons for this error, but here’s one I encountered today.

First the background. We have BizTalk server connecting to an internal Open/AS2 server running on Linux. That Linux server was re-installed on a Virtual Machine; and I had agreed with the Linux guy to change the AS2-ID (defined in the Trading Parties) from BiztalkTest to BizTalkProd. However, he didn’t make the change on his side.

So when he looked at the logs, he could see that it was receiving data, but as he described it “the server didn’t know what to do with it.” That means, it didn’t generate the MDN and send it back to BizTalk.

I had defined my SendPort was a two-way (Static Solicit-Reponse) and was using content-based routing. So we sent the message to the AS2 server, and didn’t get a response back, giving the “underlying connection closed unexpectedly” error.

Here are some samples you can use to list, start/stop, enable/disable, enlist/unenlist and so on your Send Ports, Receive Ports, and Recieve Locations.

Note the path hierarchy. You must specify you application name. I’m using “BizTalk EDI Application” since anyone with EDI installed will have the same results.

Sample Script

Add-PSSnapIn -Name BiztalkFactory.PowerShell.Extensions  #NOTE: Must be in 32-bit version of Powershellto use this SnapIn

cd "Biztalk:\Applications\BizTalk EDI Application\Send Ports"
Get-ChildItem | ft -auto      # or just type in "DIR", the "| ft -auto" avoids the Name being cut off with the elipse ... 
Write-Host "`nSend Ports - List Completed"
Get-ChildItem |Where-Object { $_.Name -match 'ResendPort' } | Unenlist-SendPort
Get-ChildItem |Where-Object { $_.Name -match 'ResendPort' } | Start-SendPort

cd "Biztalk:\Applications\BizTalk EDI Application\Receive Ports"
Get-ChildItem | ft -auto      # or just type in "DIR", the "| ft -auto" avoids the Name being cut off with the elipse ... 
Write-Host "`nReceive Ports - List Completed"

cd "Biztalk:\Applications\BizTalk EDI Application\Receive Locations"
Get-ChildItem | ft -auto      # or just type in "DIR", the "| ft -auto" avoids the Name being cut off with the elipse ... 
Write-Host "`nReceive Ports - List Completed"

cd "Biztalk:\Applications\BizTalk EDI Application\Receive Locations"
Get-ChildItem |Where-Object { $_.Name -match 'ResendReceiveLocation' } | Disable-ReceiveLocation
Get-ChildItem |Where-Object { $_.Name -match 'ResendReceiveLocation' } | Enable-ReceiveLocation

Note: I didn't put any Write-Host to show when the ports were succesfully stopped or started, you could add that i you want it.

Output of running the above script

    Path: BiztalkFactory.PowerShell.Extensions\BizTalk::Biztalk:\Applications\BizTalk EDI Application\Send Ports

Name       Status  Application            
----       ------  -----------            
ResendPort Started BizTalk EDI Application

Send Ports - List Completed

    Path: BiztalkFactory.PowerShell.Extensions\BizTalk::Biztalk:\Applications\BizTalk EDI Application\Receive Ports

Name                        Application            
----                        -----------            
BatchControlMessageRecvPort BizTalk EDI Application
ResendReceivePort           BizTalk EDI Application

Receive Ports - List Completed

    Path: BiztalkFactory.PowerShell.Extensions\BizTalk::Biztalk:\Applications\BizTalk EDI Application\Receive Locations

Name                       Enabled Application            
----                       ------- -----------            
BatchControlMessageRecvLoc True    BizTalk EDI Application
ResendReceiveLocation      True    BizTalk EDI Application

Receive Ports - List Completed

PS BizTalk:\Applications\BizTalk EDI Application\Receive Locations> 

When you install the Powershell Extensions for BizTalk, there is a readme.txt file created ("d:\Program Files (x86)\Microsoft BizTalk Server 2016\SDK\Utilities\PowerShell\readme.txt") that will show you all the cmdlets that are available (such as Start-SendPort, Unenlist-SendPort, etc...)

When dealing with Host Instances, you must specify the fully-qualified name, or use a couple of tricks I show in this blog.

I’ve been setting up some pre-canned scripts that I can just open when needed, and that have already been tested. Today I was looking at listing, starting, and stopping BizTalk Host Instances.

Powershell Script

Add-PSSnapIn -Name BiztalkFactory.PowerShell.Extensions  #NOTE: Must be in 32-bit version of Powershellto use this SnapIn

cd "Biztalk:\Platform Settings\Host Instances"
Get-ChildItem | ft -auto      # or just type in "DIR", the "| ft -auto" avoids the Name being cut off with the elipse ... 
Write-Host "`nList Completed"

#Demonstrating 3 ways: 
#  1) Use fully qualified host instance name (a big pain to type it correctly) 
#  2) Use the -match operator to match on a string 
#  3) Use the Host name instead
# With last two, it will start/stop all host-instances on all machines

Stop-HostInstance "Microsoft BizTalk Server OrchHost SERVER01"
Write-Host "Stopped"

#Get-ChildItem |Where-Object { $_.Name -match 'OrchHost' } |Start-HostInstance
Get-ChildItem |Where-Object { $_.Host -eq 'OrchHost' } |Start-HostInstance
Write-Host "Started"

Results of running the above Powershell Script

    Path: BiztalkFactory.PowerShell.Extensions\BizTalk::Biztalk:\Platform Settings\Host Instances

Name                                                           Host Name                 Windows Group                         Running Server
----                                                           ---------                 -------------                         --------------
Microsoft BizTalk Server BizTalkServerApplication SERVER01  BizTalkServerApplication  BizTalk Application Users             SERVER01   
Microsoft BizTalk Server BizTalkServerIsolatedHost SERVER01 BizTalkServerIsolatedHost BizTalk Isolated Host Users           SERVER01   
Microsoft BizTalk Server TrackingHost SERVER01              TrackingHost              SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server AS2HostReceive SERVER01            AS2HostReceive            SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server AS2HostSend SERVER01               AS2HostSend               SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server SFTPHostReceive SERVER01           SFTPHostReceive           SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server SFTPHostSend SERVER01              SFTPHostSend              SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server FileHostReceive SERVER01           FileHostReceive           SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server FileHostSend SERVER01              FileHostSend              SERVER01\BizTalk Application Users SERVER01   
Microsoft BizTalk Server OrchHost SERVER01                  OrchHost                  SERVER01\BizTalk Application Users SERVER01   

List Completed

PS BizTalk:\Platform Settings\Host Instances> 

The use of “-ft auto” is used to avoid the ellipsis and show the full name (rather than truncating it).

After you add Host and Host-Instances to BizTalk, they are not useful and cannot be associated with Send/Receive ports until you relate the Host to the Adapter. This can be done in BizTalk Admin Console, but below is a program that allows you to do it with the BizTalk Powershell Extensions.

See related script to use Powershell to add new BizTalk Hosts and Host Instances.

Add-PSSnapIn -Name BiztalkFactory.PowerShell.Extensions  #NOTE: Must be in 32-bit version of Powershellto use this SnapIn
#get-PsSnapIn -registered   ### list registered Snap-In's

function UpdateAdapter($AdapterName, $HostName, $Direction)
        # modeled after code from: 

        Write-Host "Starting of `$Adapter=$AdapterName and `$Host=$HostName `$Direction=$Direction"
        #Example: Set-Location –Path '..\SFTP'
        $Pathname = "BizTalk:\Platform Settings\Adapters\$AdapterName"
        Write-Host "`$PathName=$PathName"
        Set-Location –Path $PathName 

        if ($Direction -eq "Send" -or $Direction -eq "Both") 
            Write-Host "Setup Sending" 
            ### Sending 
                                                           #Example:  -eq "SFTP Send Handler (Sending_64)"
            $VarAdapterHandler = Get-ChildItem | Where-Object{$_.Name -eq "$AdapterName Send Handler ($HostName)"}
            if($VarAdapterHandler.Name -eq $null)
                   Write-Host "Adding $AdapterName handler for Host=$HostName"
                   #New-Item  -Path .\Sending_64 -HostName Sending_64 -Direction Send 
                   New-Item  -Path .\$HostName -HostName $HostName -Direction Send

        if ($Direction -eq "Receive" -or $Direction -eq "Both") 
            Write-Host "Setup Receiving" 
            ### Receiving
            $VarAdapterHandler = Get-ChildItem | Where-Object{$_.Name -eq "$AdapterName Receive Handler ($HostName)"}
            if($VarAdapterHandler.Name -eq $null)
                   Write-Host "Adding SFTP Receive handler for Receiving_64 Host"
                   New-Item  -Path .\$Hostname -HostName $HostName -Direction Receive
        Write-Host "End of $AdapterName and $HostName"
        Write-Host "----"


### MAIN CODE HERE - Calls Function Above once per Host/Host-Instance ### 

#Pass Three Parms: 1) AdapterName, 2) HostName, 3) Direction [Send/Recive/Both]
#UpdateAdapter  "TrackingHost"   "Both" 

UpdateAdapter "HTTP" "AS2HostReceive" "Receive"
UpdateAdapter "HTTP" "AS2HostSend"    "Send"

UpdateAdapter "SFTP" "SFTPHostReceive" "Receive"
UpdateAdapter "SFTP" "SFTPHostSend"    "Send"

UpdateAdapter "FILE" "FileHostReceive" "Receive"
UpdateAdapter "FILE" "FileHostSend"    "Send"

Write-Host "Script Completed"

The following shows how to set the $HostType for the BizTalk Powershell Extensions.

 if ($HostType -eq "Isolated") 
     $HostTypeCode = 2  #Isolated 
     $HostTypeCode = 1  #In-Process
 $temp = New-Item -path $hostName -HostType:$HostTypeCode -NtGroupName:$myNTHostGroupName -AuthTrusted:$AuthTrusted 

See full function in this blog about Adding BizTalk Hosts and Hostinstances with Powershell.

In a previous blog, I gave a full Powershell Script to Add BizTalk Hosts, but it didn’t show how to set the 32-bit vs 64-bit flag (it has now been updated to include that).

64 bit vs 32 bit Host

In BIzTalk, the flag is called the 32BitOnly flag.  To create a 64-bit Host, set this flag to false (same as unchecking it in the BizTalk Admin Console).

Instead of setting it on the New-Item command, you have to set it as a property on the following line of code, as shown below.

Code Sample

$temp = New-Item -path $hostName -HostType:$HostType -NtGroupName:$myNTHostGroupName -AuthTrusted:$AuthTrusted 
Set-ItemProperty -Path $hostName -Name 'Is32BitOnly' -Value 'False'
#similarly, to set whether or not the Host is a "Tracking Host", use the following line 
Set-ItemProperty -Path $hostName -Name 'HostTracking' -Value 'True' 

To get a list of all the miscellaneous properties, I set a break point and use the Get-Members cmdlet:

[DBG]: PS BizTalk:\Platform Settings\Hosts>> $temp | Get-Member

   TypeName: BizTalkFactory.Management.Automation.BtsHost

Name                                  MemberType   Definition                                                                                
----                                  ----------   ----------                                                                                
Equals                                Method       bool Equals(BizTalkFactory.Management.Automation.BtsArtifact other), bool Equals(System...
ExportHostSettings                    Method       void ExportHostSettings(string path)                                                      
GetHashCode                           Method       int GetHashCode()                                                                         
GetType                               Method       type GetType()                                                                            
ImportHostSettings                    Method       void ImportHostSettings(string path)                                                      
ToString                              Method       string ToString()                                                                         
PSChildName                           NoteProperty System.String PSChildName=TrackingHost                                                    
PSDrive                               NoteProperty BizTalkFactory.PowerShell.Extensions.BizTalkDriveInfo PSDrive=BizTalk                     
PSIsContainer                         NoteProperty System.Boolean PSIsContainer=False                                                        
PSParentPath                          NoteProperty System.String PSParentPath=BiztalkFactory.PowerShell.Extensions\BizTalk::Biztalk:\Platf...
PSPath                                NoteProperty System.String PSPath=BiztalkFactory.PowerShell.Extensions\BizTalk::Biztalk:\Platform Se...
PSProvider                            NoteProperty System.Management.Automation.ProviderInfo PSProvider=BiztalkFactory.PowerShell.Extensio...
AllowMultipleResponses                Property     bool AllowMultipleResponses {get;set;}                                                    
AuthTrusted                           Property     bool AuthTrusted {get;set;}                                                               
Catalog                               Property     BizTalkFactory.Management.Automation.BtsCatalog Catalog {get;}                            
Clustered                             Property     bool Clustered {get;}                                                                     
DBQueueSizeThreshold                  Property     uint32 DBQueueSizeThreshold {get;set;}                                                    
DBSessionThreshold                    Property     uint32 DBSessionThreshold {get;set;}                                                      
DehydrationBehavior                   Property     BizTalkFactory.Management.Automation.BtsDehydrationBehavior DehydrationBehavior {get;set;}
DeliveryQueueSize                     Property     uint32 DeliveryQueueSize {get;set;}                                                       
GlobalMemoryThreshold                 Property     uint32 GlobalMemoryThreshold {get;set;}                                                   
HostTracking                          Property     bool HostTracking {get;set;}  
HostType                              Property     BizTalkFactory.Management.Automation.BtsHostType HostType {get;}                          
InflightMessageThreshold              Property     uint32 InflightMessageThreshold {get;set;}                                                
Is32BitOnly                           Property     bool Is32BitOnly {get;set;}  
IsDefault                             Property     bool IsDefault {get;set;}                                                                 
IsHost32BitOnly                       Property     bool IsHost32BitOnly {get;set;}                                                           
LegacyWhitespace                      Property     bool LegacyWhitespace {get;set;}                                                          
MessageDeliveryMaximumDelay           Property     uint32 MessageDeliveryMaximumDelay {get;set;}                                             
MessageDeliveryOverdriveFactor        Property     uint32 MessageDeliveryOverdriveFactor {get;set;}                                          
MessageDeliverySampleSpaceSize        Property     uint32 MessageDeliverySampleSpaceSize {get;set;}                                          
MessageDeliverySampleSpaceWindow      Property     uint32 MessageDeliverySampleSpaceWindow {get;set;}                                        
MessagePublishMaximumDelay            Property     uint32 MessagePublishMaximumDelay {get;set;}                                              
MessagePublishOverdriveFactor         Property     uint32 MessagePublishOverdriveFactor {get;set;}                                           
MessagePublishSampleSpaceSize         Property     uint32 MessagePublishSampleSpaceSize {get;set;}                                           
MessagePublishSampleSpaceWindow       Property     uint32 MessagePublishSampleSpaceWindow {get;set;}                                         
MessagingMaxReceiveInterval           Property     uint32 MessagingMaxReceiveInterval {get;set;}                                             
MessagingReqRespTTL                   Property     uint32 MessagingReqRespTTL {get;set;}                                                     
MsgAgentPerfCounterServiceClassID     Property     guid MsgAgentPerfCounterServiceClassID {get;set;}                                         
Name                                  Property     string Name {get;}                                                                        
NtGroupName                           Property     string NtGroupName {get;}                                                                 
ProcessMemoryThreshold                Property     uint32 ProcessMemoryThreshold {get;set;}                                                  
SubscriptionPauseAt                   Property     uint32 SubscriptionPauseAt {get;set;}                                                     
SubscriptionResumeAt                  Property     uint32 SubscriptionResumeAt {get;set;}                                                    
ThreadPoolSize                        Property     uint32 ThreadPoolSize {get;set;}                                                          
ThreadThreshold                       Property     uint32 ThreadThreshold {get;set;}                                                         
ThrottlingBatchMemoryThresholdPercent Property     uint32 ThrottlingBatchMemoryThresholdPercent {get;set;}                                   
ThrottlingDeliveryOverride            Property     uint32 ThrottlingDeliveryOverride {get;set;}                                              
ThrottlingDeliveryOverrideSeverity    Property     uint32 ThrottlingDeliveryOverrideSeverity {get;set;}                                      
ThrottlingLimitToTriggerGC            Property     uint32 ThrottlingLimitToTriggerGC {get;set;}                                              
ThrottlingPublishOverride             Property     uint32 ThrottlingPublishOverride {get;set;}                                               
ThrottlingPublishOverrideSeverity     Property     uint32 ThrottlingPublishOverrideSeverity {get;set;}                                       
ThrottlingSeverityDatabaseSize        Property     uint32 ThrottlingSeverityDatabaseSize {get;set;}                                          
ThrottlingSeverityInflightMessage     Property     uint32 ThrottlingSeverityInflightMessage {get;set;}                                       
ThrottlingSeverityProcessMemory       Property     uint32 ThrottlingSeverityProcessMemory {get;set;}                                         
ThrottlingSpoolMultiplier             Property     uint32 ThrottlingSpoolMultiplier {get;set;}                                               
ThrottlingTrackingDataMultiplier      Property     uint32 ThrottlingTrackingDataMultiplier {get;set;}                                        
TimeBasedMaxThreshold                 Property     uint32 TimeBasedMaxThreshold {get;set;}                                                   
TimeBasedMinThreshold                 Property     uint32 TimeBasedMinThreshold {get;set;}                                                   
UseDefaultAppDomainForIsolatedAdapter Property     bool UseDefaultAppDomainForIsolatedAdapter {get;set;}                                     
XlangMaxReceiveInterval               Property     uint32 XlangMaxReceiveInterval {get;set;}                                                 

[DBG]: PS BizTalk:\Platform Settings\Hosts>> 

Error: No snaps-ins have been registered for Windows PowerShell

You run the following:

Add-PSSnapIn -Name BiztalkFactory.PowerShell.Extensions  #NOTE: Must be in 32-bit version of Powershellto use this SnapIn


And you get this error:

Add-PSSnapIn : No snap-ins have been registered for Windows PowerShell version 3.


Solution:Go the SDK/Utilities/Powershell and install them

Basically follow the steps laid out by here MSDN BizTalk Forum, except you don’t need to download from CodePlex, you can use the one in the install.

  1. Navigate to: C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\SDK\Utilities\PowerShell
  2. Optionally open and follow the readme.txt
  3. Open a command prompt as an administrator
  4. Change directory to the folder containing the binaries – \SDK\Utilities\PowerShell under the base install location
  5. Run the following command to install/register the dlls
    %windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe .\BizTalkFactory.PowerShell.Extensions.dll

I needed this today to run a powershell to create biztalk hosts.

The following may help with a variety of custom pipeline component issues, including why your “Debug” is not catching when you expect it to. There were times today, where I would do “Debug Attach” to the BizTalk Host Instance, and the component would never go into debug mode.

1. Check that date/time of the .DLL in the GAC. There’s a chance you compiled it and though you GAC’ed it but it didn’t. Here’s the folder name to check:


You might be using a Post Build Event like this to GAC the .DLL:

which is placed in the project properties dialog as shown below:

Check your View/Output in Visual Studio to see if you have message that it did or didn’t GAC successfully:

Example Successful GAC
1>  Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
1>  Copyright (c) Microsoft Corporation.  All rights reserved.
1>  Assembly successfully added to the cache
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Example Failed GAC
1>  Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
1>  Copyright (c) Microsoft Corporation.  All rights reserved.
1>  Failure adding assembly to the cache:   The process cannot access the file because it is being used by another process.
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): error MSB3073: The command "CALL "%VS140COMNTOOLS%vsvars32.bat"
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): error MSB3073: gacutil.exe /i "C:\Users\nrwalters\Documents\Visual Studio 2015\Projects\ABC.Common\ABC.Common.BizTalkPipelineComponentEmail\bin\Debug\ABC.Common.BizTalkPipelineComponentEmail.dll"" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========

Sometimes you have to close Visual Studio, then re-open it and do the ReBuild.
Once I was just doing “Build” and since the code didn’t change, it wasn’t rebuilding, and thus it wasn’t running the Post-Build Event, and thus the GAC didn’t get changed!

Other Steps

2. Always restart your host instance. If you have more than one, make sure you picked the right one.

3. When you do Debug Attach – you also have to make sure you select the proper BTNTSvc.exe. Use Task Manager to get the process ID based on the name, and then in Visual Studio, select based on the “ID” column.

Pipeline Components Directory?

Some blogs say that since BT 2006 this isn’t really needed; that you should just GAC your pipeline components.
Other people argue that it is still necessary. I seem to have success with the first otpion.


The adapter failed to transmit message going to send port “sp_Test_SFTP” with URL “s”. It will be retransmitted after the retry interval specified for this Send Port. Details:”System.IO.FileLoadException: Could not load file or assembly ‘WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’ or one of its dependencies. General Exception (Exception from HRESULT: 0x80131500)
File name: ‘WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’ —> System.Exception: SFTP adapter requires WinSCP to be installed. Please refer . —> System.IO.FileNotFoundException: Could not load file or assembly ‘file:///C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.BizTalk.Adapter.Sftp\v4.0_3.0.1.0__31bf3856ad364e35\WinSCPnet.dll’ or one of its dependencies. The system cannot find the file specified.


I think BizTalk requires a specific older version of WinSCP and you can’t just download the latest one.
This error could also occur if you didn’t copy the file to the proper directly.

I found Michael Stephenson’s BizTalk 2016 SFTP blog, and it had a nice PowerShell script.

I just had to
1) Change directory names (I had a Software directory similar to him, but I had to create a WinSCP subdirectory under it)
2) Then PowerShell with the “Run as Admin” option.

Then the script ran fine, I restarted BizTalk Host Instance, and it got past this error, on to other errors that I’ll blog about in the near future.

By the way, I was able to run in a 64-bit host with no problem.  I remember that in older version of BizTalk the FTP adapter ran only in 32-bit hosts.




I started with this excellent working unzip pipeline component here (by Rui Machado).

I made the following changes to that code:
1) Put it in MyCompany.Common.etc… namespace and project (not shown here)
2) Added a Property Bag Item called FileMask (and a one for future use called “ParmReserved1” (this is standard coding, so I didn’t include here).
3) Added the FitsMask function from StackOverflow
4) Added the functionality to set the %SourceFileName% (aka ReceivedFileName, based on the files inside the zip instead of the zip file dropped).

public void Disassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
  IBaseMessage Temp = inmsg;
  // uses Ionic.Zip 
  using (ZipFile zip = ZipFile.Read(inmsg.BodyPart.GetOriginalDataStream()))
    foreach (ZipEntry e in zip)
      string strCheckFileName = System.IO.Path.GetFileName(e.FileName);

      if (FitsMask(strCheckFileName, FileMask))
         var ms = new MemoryStream();
         IBaseMessage outMsg;
         outMsg = pc.GetMessageFactory().CreateMessage();
         outMsg.AddPart("Body", pc.GetMessageFactory().CreateMessagePart(), true);
         outMsg.Context = inmsg.Context;

        // Neal Walters - 05/08/2017 - added promoted field with the filename - 
        // This allows us to use the %sourcefilenam% macro in the SendPort to name the file. 

        string XMLMessage = Encoding.UTF8.GetString(ms.ToArray());

        MemoryStream mstemp = new System.IO.MemoryStream(

        outMsg.GetPart("Body").Data = mstemp;


        private static bool FitsMask(string fileName, string fileMask)
            string pattern =
                 '^' +
                 Regex.Escape(fileMask.Replace(".", "__DOT__")
                                 .Replace("*", "__STAR__")
                                 .Replace("?", "__QM__"))
                     .Replace("__DOT__", "[.]")
                     .Replace("__STAR__", ".*")
                     .Replace("__QM__", ".")
                 + '$';
            return new Regex(pattern, RegexOptions.IgnoreCase).IsMatch(fileName);

The screen shot below show how the FileMask can be specified in the RecieveLocation (via use of the standard Property Bag interface):

(Sorry, don't have SnagIt yet at this client, so have to use the poor man's Snipping Tool).