I’m having trouble downloading file with asp.net mvc2. This is how I do it in my download action:
return File(resultBytes, Settings.Default.CsvFileContentType, downloadName);
The problem is with the downloadName, this is how I generate it:
var downloadName = string.Format("{0}_{1}{2}", vModel.CompetitionEvent.Ends.Year, Text.RemoveDiacriticalChars(vModel.Competition.Title), Settings.Default.CsvFileExtension);
and when I debug, downloadName value is: “2011_SS C/C++/Pascal (I.).csv”
but what I get upon downlaod is: “Pascal (I.).csv”.
Does anyone have an idea why this happens?
You simply cannot have a “/” character in a filename. Windows filenames in general cannot contain “\/:*?”<>|”, so I assume the downloadname is being automatically truncated to adhere to this limitation.
Try replacing the “/” with a hypen (“-“) instead, and see what happens 🙂