Many times developers want to get rid off from file uploading. Actually in many scenarios they have to upload multiple files at once, also they have to check file types during upload. This checking limits to end users from uploading wrong desired files to upload.
There are many solutions available in ASP.Net, jQuery, AJAX and many other client side scripting languages. In my opinion, jQuery does well above mentioned scenario.
To use jQuery multiple file upload along with file checking and number of files to upload at once, I briefly shown example below.
- First of all download files from http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Download
- Extract all files and into root directory
- Open Visual Studio
- Create new website
- Add new webpage
- Add following code in header section of .aspx page
- <script type=”text/javascript” src=”Scripts/jquery-1.3.2.js”></script>
- <script src=”Scripts/jquery.MultiFile.js” type=”text/javascript”></script>
- Add form tag like
- <form runat=server id=”form1″ encType=”multipart/form-data”>
- Add file upload control, code will be like
- <asp:FileUpload ID=”fu1″ runat=”server” Width=”250px” accept=”gif|jpg” maxlength=”1″/>
- Add button like
- <asp:Button ID=”btn_upload” runat=”server” OnClick=”btn_upload_Click” Text=”Upload Picture” />
Now come to function behind btn_upload_Click
Add following code in button event
string path = “Pics”;
if (fu1.PostedFile != null)
{
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
if (File.Exists(path) == true)
{
try
{
System.IO.File.Delete(“path to physical file “);
catch (Exception r)
{}
}
}
else
{
hpf.SaveAs(Server.MapPath(path));
}
}
}
}
Now come to description of the jQuery file Upload
accept=”gif|jpg” maxlength=”3″, accept character restricts end users to select only defined extionsions of files and maxlength defines how much files will be uploaded at once.
Pingback: iasbet
Pingback: antoninus pius coins
Pingback: linkwheel
Pingback: Uncover Coupon For Bed Bath And Beyond
Pingback: Bed Bath and Beyond Printable Coupons - What you should Look Out For
Great post!
whoah this blog is magnificent i love studying your posts. Keep up the good paintings! You realize, lots of persons are searching around for this info, you can aid them greatly.
Simply wanna comment that you have a very nice web site , I love the design it really stands out.
colorblock heels shop here
Simply wish to say your article is as astounding. The clarity for your post is just excellent and i could assume you’re a professional on this subject. Well with your permission allow me to seize your RSS feed to keep updated with approaching post. Thank you 1,000,000 and please continue the enjoyable work.
Jasa Setting Mikrotik dan Proxy Cepat
I gotta bookmark this web site it seems extremely helpful extremely helpful.
Some truly prime content on this website , saved to fav.