As Mr.koolprasd2003 mentioned,
you have to set
Response.ContentType first, but to know the content type by using fileextenctions you can use this method
public string getContentType(string extension)
{
const string DEFAULT_CONTENT_TYPE = "application/unknown";
RegistryKey regkey, fileextkey;
string filecontenttype;
string fileextension = extension;
try
{
regkey = Registry.ClassesRoot;
fileextkey = regkey.OpenSubKey(fileextension);
filecontenttype = fileextkey.GetValue("Content Type", DEFAULT_CONTENT_TYPE).ToString();
fileextkey = null;
regkey = null;
}
catch
{
filecontenttype = DEFAULT_CONTENT_TYPE;
}
return filecontenttype;
}
Response.ContentType = getContentType(".jpg");
Response.AppendHeader("Content-Disposition", "Filename");