0

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 Answers 2

2
// 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);
Sign up to request clarification or add additional context in comments.

1 Comment

To be complete I would add a Response.Flush() and Response.Close() after the Write.
1

Here is the complete list of common MIME types.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.