Saturday, March 31, 2012

How to save the Image using IHttpHandler in asp.net

The Http process will be used to save the image in database.Here one more class is used to do the data base functionality and The GetUploadBinary method is used to update the image data in data base
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request.Files.Count == 0)
{
context.Response.Write("No files uploaded.");
return;
}
int id;
if (String.IsNullOrEmpty(context.Request.QueryString["itemId"]) || !Int32.TryParse(context.Request.QueryString["itemId"], out id))
{
context.Response.Write("No item id provided.");
return;
}

TestDataContext tdc = new TestDataContext(Config.ConnectionString);
Orders item = tdc.Orders.FirstOrDefault(p => p.ID.Equals(id));
if (item == null)
{
context.Response.Write("Item not found.");
return;
}
item.Image = SiteUtility.GetUploadBinary(context.Request.Files[0]);
item.ImageType = context.Request.Files[0].ContentType;
tdc.SubmitChanges();
}
Post a Comment

Bel