谁在asp.net中使用filedrop插件上传文件

时间:2013-03-30 11:03:07

标签: javascript asp.net html file-upload

我尝试按文件下载插件上传文件,但我无法在UploadHandler.ashx中获取该文件

我需要做的是上传文件

<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>

和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());

如何通过context.Request.Files获取文件;

3 个答案:

答案 0 :(得分:0)

试试这个:

Request.InputStream.CopyTo(new FileStream("c:\\temp\" + Request.Params["HTTP_X_FILE_NAME"], FileMode.CreateNew));

答案 1 :(得分:0)

也许你可以看看这个:http://html5demos.com/file-api 还有一些类似的问题:HTML5 FileReader alternative

答案 2 :(得分:0)

你应该这样写:

     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;
 }