Crystal Reports: Display File Name without Path

From time to time you will want to display the file name of a Crystal Report in the report so that you can find the report faster to work on it.  Crystal Reports has a built-in Special Field called File Path and Name.  It works and displays the file name but also the full UNC path of where the file is located.  The whole path is too much information to publish to anyone who may view the report and in some cases takes up too much real estate on the page.  Here is how you get around that.

The first thing to do is to create a new Formula Field and name it FileNameOnly or something descriptive to help you or one of your coworkers quickly identify the field and its purpose.  When the new field prompts you for the formula, paste in of the options below.

 

Option 1: Show only the file name and the file’s extension:

 

filename [ InstrRev ( filename , '\') + 1  to Length (FileName) ]

 

Option 2: Show the file name without the file’s extension:


filename [ InstrRev ( filename , '\') + 1  to Length (FileName) - 4 ]

 

You might find that you want to display more or less than that what is visible with the code snippets above, so be sure to play around with the values and massage it so the output is to your liking.

Take care and be safe.