c# - Uploading images with asp.net generic handler -


i trying upload multiple files using following code.

html & jquery

<%@ page language="c#" autoeventwireup="true" codebehind="webform1.aspx.cs" inherits="fileupload.webform1" %>  <!doctype html>  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>      <script src="scripts/jquery-1.8.2.min.js"></script>     <script src="scripts/jquery-ui-1.8.24.min.js"></script>     <link href="content/themes/base/jquery.ui.all.css" rel="stylesheet" /> </head> <body>     <form id="form1" runat="server">         <asp:fileupload id="fileupload1" runat="server" allowmultiple="true" />         <br />         <br />         <asp:button id="button1" runat="server" text="upload selected file(s)" />         <div id="progressbar"></div>     </form>     <script type="text/javascript">         $(document).ready(function () {             $("#progressbar").progressbar({ value: 0 });             $("#button1").click(function (evt) {                  var fileupload = $("#fileupload1").get(0);                 var files = fileupload.files;                  var data = new formdata();                 (var = 0; < files.length; i++) {                     data.append(files[i].name, files[i]);                 }                  var options = {};                 options.url = "upload.ashx";                 options.type = "post";                 options.data = data;                 options.asyn = true;                 options.contenttype = false;                 options.processdata = false;                 options.datatype = "application/json; charset=utf-8";                 options.success = function (data) {                     var length = data.length;                     (var = 0; < length; i++) {                         updateprogress();                     }                      $("#progressbar").progressbar("value", 100);                 };                 options.error = function (err) { alert(err.statustext); };                  $.ajax(options);                  evt.preventdefault();             });         });          function updateprogress() {             var value = $("#progressbar").progressbar("option", "value");             if (value < 100) {                 $("#progressbar").progressbar("value", value + 1);             }         }     </script> </body> </html> 

c# handler

using system; using system.collections.generic; using system.linq; using system.web;  namespace fileupload {     /// <summary>     /// summary description upload     /// </summary>     public class upload : ihttphandler     {          public void processrequest(httpcontext context)         {             if (context.request.files.count > 0)             {                 httpfilecollection files = context.request.files;                 (int = 0; < files.count; i++)                 {                     httppostedfile file = files[i];                     string fname = context.server.mappath("~/upload/" + file.filename);                     file.saveas(fname);                 }             }             context.response.contenttype = "text/plain";             context.response.write("file(s) uploaded successfully!");         }          public bool isreusable         {                         {                 return false;             }         }     } } 

i have jquery ui progress bar updates based on percentage completed. upload 1 file. when select multiple files upload, gives internal server error. progress bar not working @ in either of cases (uploading 1 file or multiple file)

could have , wrong in code?

thanks,

update

i got multiple files issues sorted. still couldnt progress bar updating.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -