Lurking in my web.config file for the MVC application that had been forced upon me was a line for acceptable file types:
<add key="ValidFileAttachmentTypes" value=".xls,.xlsx,.doc,.docx,.txt,.pdf" />
In addition to its more useful features, I wanted to display this string in my view to show users who would be uploading their horrid little files (I jest, sort-of) to the system.
So I write this terribly complex code to do so:
@Html.Label("Valid file types are: " + ConfigurationManager.AppSettings["ValidFileAttachmentTypes"])
And what’s its output: pdf
Watchoo talkin’ ’bout, Willis? That ain’t be what I wanted. (Reading that sentence makes want to 1) Watch “Diff’rent Strokes” and 2) Listen to “Word Crimes” by Weird Al Yankovic).
The solution was to use the string Replace method and replace the periods with empty spaces:
@Html.Label("Valid file types are: " + ConfigurationManager.AppSettings["ValidFileAttachmentTypes"].Replace('.',' '))
Tout va bien.