This is Handler Im using but still doc and .xlsx files are nt displaying.
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Net;
public class Handler : IHttpHandler {
//string FileExtension;
public void ProcessRequest (HttpContext context) {
SqlConnection con = con_manager.getcon();
string sql = "SELECT * FROM file_upload " +
"WHERE row_id=@ScanID";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add("@ScanID", SqlDbType.VarChar).Value = context.Request.QueryString["id"];
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read()) //yup we found our image
{
// context.Response.ContentType = "application/pdf";
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
string temp=System.IO.Path.GetExtension(dr["file_name"].ToString());
switch (temp)
{
case "pdf":
context.Response.ContentType = "application/pdf";
break;
case "doc":
context.Response.ContentType = "application/msword";
break;
case "docx":
context.Response.ContentType = "application/vnd.ms-word.document.12";
break;
case "xls":
context.Response.ContentType = "application/vnd.ms-excel";
break;
case "xlsx":
context.Response.ContentType = "application/vnd.ms-excel.12";
break;
default:
context.Response.ContentType = "image/jpeg";
break;
}
// context.Response.BinaryWrite(buffer);
// context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spre";
context.Response.BinaryWrite((byte[])dr["imagedata"]);
}
con.Close();
}
public bool IsReusable {
get {
return false;
}
}
}
Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator