<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.IO;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpPostedFile file = context.Request.Files["Filedata"];
Stream FileStream = file.InputStream;
//MemoryStream ms = new MemoryStream();
BinaryReader br = new BinaryReader(FileStream);
byte[] bytes = br.ReadBytes((Int32)FileStream.Length);
//FileStream.CopyTo(ms);
//Byte[] buffer = ms.ToArray();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UploadifyTest"].ToString()))
{
con.Open();
SqlCommand cmd = new SqlCommand("Insert Into Uploadify (Name, Image,Contenttype) values (@Name, @Image,@Contenttype)", con);
cmd.Parameters.Add("@Name", SqlDbType.VarChar, 500).Value = file.FileName;
cmd.Parameters.Add("@Contenttype", SqlDbType.NVarChar, 500).Value = file.ContentType;
cmd.Parameters.Add("@Image", SqlDbType.VarBinary, int.MaxValue).Value =bytes;
cmd.ExecuteNonQuery();
}
context.Response.StatusCode = 200;
}
public bool IsReusable
{
get
{
return false;
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link rel="Stylesheet" type="text/css" href="CSS/uploadify.css" />
<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="scripts/jquery.uploadify.js"></script>
</head>
<body>
<form id="form1" runat="server">
<a href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadStart()">Start Upload</a>
| <a href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadClearQueue()">Clear</a>
<div style = "padding:40px">
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
</form>
</body>
</html>
<script type = "text/javascript">
$(window).load(
function () {
$("#<%=FileUpload1.ClientID%>").fileUpload({
'uploader': 'scripts/uploader.swf',
'cancelImg': 'images/cancel.png',
'buttonText': 'Browse Files',
'script': 'Handler.ashx',
'multi': true,
'auto': false
});
}
);
</script>
sir in contenttype in database it shows octet-stream always