c# - Web: View raw content of a file from the FileName and the FileContent -


i'm using asp mvc, , want allow user download/view files web server.

the files not located in web server.

i know file content (a byte[] array), , file name.

i want same behavior web broswer. example, if mime type text, want see text, if it's image, same, if it's binary, propose download.

what best way this?

thanks in advanced.

the answer images available here

for other types, have determine mime type file name extension. can use either windows registry or well-known hashtable, or iis configuration (if running on iis).

if plan use registry, here code determines mime content type given extension:

    public static string getregistrycontenttype(string filename)     {         if (filename == null)             throw new argumentnullexception("filename");          // determine extension         string extension = system.io.path.getextension(filename);          string contenttype = null;         using (microsoft.win32.registrykey key = microsoft.win32.registry.classesroot.opensubkey(extension))         {             if (key != null)             {                 object ct = key.getvalue("content type");                 key.close();                 if (ct != null)                 {                     contenttype = ct string;                 }             }         }         if (contenttype == null)         {             contenttype = "application/octet-stream"; // default content type         }         return contenttype;     } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -