CodeYun
CodeYun

Reputation: 749

How to open a file from browser by using asp.net c# code

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.

Upvotes: 0

Views: 3412

Answers (2)

jdecuyper
jdecuyper

Reputation: 3963

Here is the complete list of common MIME types.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039458

// 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);

Upvotes: 2

Related Questions