That string ain’t right, MVC edition

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.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: