Saturday, October 2, 2010

Upload File using JQuery in Asp.Net

There is 3 parts

1. JQuery Javascript file
2. Aspx Page Integration
3. Upload code on aspx.cs


1. JQuery Javascript file
=================================================================================
2 Files Needed to integrate that are as follows
a. jquery-1.3.2.js
b. jquery.MultiFile.js // To upload multiple files using JQuery


2. Aspx Page Integration
===============================================================================
Inculde jquery-1.3.2.js, in your aspxpage










3. Upload code on aspx.cs
==============================================================================
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
hpf.SaveAs(Server.MapPath("MyFiles") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
Response.Write("File: " + hpf.FileName + " Size: " +
hpf.ContentLength + " Type: " + hpf.ContentType + " Uploaded Successfully
");
}
}
}
catch (Exception ex)
{

}
}

Here I am attaching the whole source code thourgh which all of you can easly understand how it will works

No comments:

Post a Comment