tags:

views:

51

answers:

1

I have an asp.net mvc action that returns a file result. Behind the scenes, it's just returning a file from a directory. FilePathResult requires a content type, but I don't know that.

What is the proper way to return a file result if I only have the path to the file available?

+1  A: 

Take the file extention, and look it up in the regeistry. The entry for it will have a "Content type" property.

var reg = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (reg != null)
    contentType =   reg.GetValue("Content Type") as string;
James Curran
@James Thanks! I was worried about performance implications of this but it seems like it's the only way. I'll just store the values in cache, I guess.
Jim Geurts