-1

I try to upload a file by file drop plugin but I can not get the file in UploadHandler.ashx

What do I need to do is to upload a file

<fieldset id="zone">
  <legend>Drop a file inside&hellip;</legend>
  <p>Or click here to <em>Browse</em>..</p>
</fieldset>

<script type="text/javascript">
    // Tell FileDrop we can deal with iframe uploads using this URL:
    var options = { iframe: { url: 'UploadHandler.ashx'} };
    // Attach FileDrop to an area:
    var zone = new FileDrop('zone',options);

    // Do something when a user chooses or drops a file:
    zone.on.send.push(function (files) {
        alert(files.count.toString());
        // if browser supports files[] will contain multiple items.
        for (var i = 0; i < files.length; i++) {
            files[i].SendTo('UploadHandler.ashx');
            //var file = files[i];
        }
    });
</script>

and UploadHandler.ashx

context.Response.ContentType = "text/plain";
        HttpFileCollection httpfiles = context.Request.Files;
        for (int i = 0; i < httpfiles.Count; i++)
        {
            HttpPostedFile file = httpfiles[i];
            file.SaveAs(@"C:\"+ Path.GetFileName(file.FileName.ToString()));
        }
        context.Response.Write(httpfiles.Count.ToString());

How do I get the file by context.Request.Files;

Hossein Rahmati
  • 205
  • 1
  • 2
  • 11

3 Answers3

0

Try this:

Request.InputStream.CopyTo(new FileStream("c:\\temp\" + Request.Params["HTTP_X_FILE_NAME"], FileMode.CreateNew));
jeroen.verhoest
  • 5,173
  • 2
  • 27
  • 27
0

Maybe you can have a look at this: http://html5demos.com/file-api Also some similar question here: HTML5 FileReader alternative

Community
  • 1
  • 1
Setup
  • 330
  • 2
  • 21
0

You should write like this:

     HttpPostedFile  file;
  for(int i=0;i<context.Request.Files.Count;i++)
 {
  file=context.Reqeust.Filed[i];//this can get your file 
  //do something about the file;
 }