views:

121

answers:

2

From Service method return me:

String FileName,
Byte[] FileData, 
string FileType( includes:  doc, pdf, tif, tiff, gif, jpg, jpeg, png, bmp, wpd)

How can I generate a file based on filetype and show it to user in browser? Download to user is ok for me

+2  A: 
// You will need to figure out the correct content type based on the file type 
// for example image/jpeg for jpeg files
Response.ContentType = ...;
var cd = new ContentDisposition()
{
    Inline = true,
    FileName = FileName
};
Response.AppendHeader("Content-Disposition", cd.ToString());
Response.OutputStream.Write(FileData, 0, FileData.Length);
Darin Dimitrov
To be complete I would add a Response.Flush() and Response.Close() after the Write.
tomlog
+1  A: 

Here is the complete list of common MIME types.

jdecuyper