Description:-
In
Pevious we Already Explain How to Upload Multiple File in Database in MVC now
we Explain How to Upload Multiple File in SqlServer Database Using Jquery in
Asp.Net.
Here We use Generic Handler Class to
Upload Multiple File in database.before we Explain we First understand the what
is Generic handler Class.
What is Generic handler Class:-
Generic
handler is nothing but a same like aspx page and the extention of this file is
.ashx.Generally Generic Handler class are used to Response the Request and
Request is Proceed by the page Handler. You can also create your own HTTP
Handler and that renders the output to the browser.
In this Example we Provide Facility to
user to Browse a Multiple File at a time and Uploading all Browse File at a
time with Prgressbar Facility same like provide in GMAIL when we send the Email
with Atteched the File. This is simply done with JQuery and we will Requst the
Response using Generic Handler.
to show Example of Javascript Validation that aalow only number in TextBox Disable all the keyboard key Excvept only Number
to show Example of Rotate the Advertise in webpage Rotate Ads without Refresh the page
to Download Complete example click below Image link
TriggerUpload.aspx:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TriggerUpload.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head 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': 'Upload.ashx',
'folder': 'uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': true,
'auto': false
});
}
);
</script>
Upload.ashx:-
<%@ WebHandler Language="C#" Class="Upload" %>
using
System;
using
System.Web;
using
System.IO;
public class Upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
string savepath = "";
string tempPath = "";
tempPath
= System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
savepath
= context.Server.MapPath(tempPath);
string filename = postedFile.FileName;
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
postedFile.SaveAs(savepath + @"\" + filename);
context.Response.Write(tempPath + "/" + filename);
context.Response.StatusCode = 200;
}
catch (Exception ex)
{
context.Response.Write("Error:
" + ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}
screen shot looks different.
ReplyDeleteit is just demo.thanks
Delete