ADF Switch Expression Adding Unexpected Characters to FileName

Steve Jamrose 20 Reputation points
2025-03-03T01:20:18.6566667+00:00

The pipeline involves a file landing in an SFTP Blob container, which is decrypted by a .Net application. After the decryption and movement to a designated folder, a pipeline is triggered to load the file into a SQL table.

A Get Metadata activity successfully retrieves the FileName ChildItems into a variable activity. The "FileNameVariable" extracts the "FileName" and passes it to a Switch expression as follows:

  • @activity('Get Metadata1').output.childItems[0].name

The Switch expression uses "Contains" logic:

  • @{if(contains(variables('FileNameVariable'), 'ExampleCase1'),'ExampleCase1', 'Default')}

During debugging, the filename in "FileNameVariable" correctly holds the full filename. However, the expression in the switch evaluates the "FileNameVariable" with unexpected characters like "ExampleCase1 /n/n:", which causes the switch to revert to the default case instead of matching properly.

What could be the reason for the addition of the /n/n or /t/n characters to the end of the filename? Any insights would be appreciated.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,323 questions
{count} votes

Accepted answer
  1. Amira Bedhiafi 29,711 Reputation points
    2025-03-03T11:09:43.1133333+00:00

    Try to trim the filename to remove any leading or trailing whitespace or newline characters before using it in the switch expression :

    
       @{if(contains(trim(variables('FileNameVariable')), 'ExampleCase1'), 'ExampleCase1', 'Default')}
    
    

    Or use the toString() function to make sure that the variable is treated as a string.

    
       @{if(contains(toString(variables('FileNameVariable')), 'ExampleCase1'), 'ExampleCase1', 'Default')}
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.