asp.net c #javascript拖放文件上传在Firefox 45中不起作用

时间:2016-03-11 13:34:03

标签: javascript c# asp.net file-upload drag-and-drop

由于Firefox昨天更新到v45,我的拖放文件上传不再有效。这是Firefox中的错误还是我必须对我的代码进行一些更改? Chrome仍然可以正常工作,也可以在IE,Edge doenst工作。

这是我在aspx文件中的代码:

function handleDragOver(event) {
    event.stopPropagation();
    event.preventDefault();
    var dropZone = document.getElementById('drop_zone');
}
function handleDnDFileSelect(event) {
    event.stopPropagation();
    event.preventDefault();    
    files = event.dataTransfer.files;
    var form = document.getElementById('form1');
    var data = new FormData(form);

    for (var i = 0; i < files.length; i++) {
        data.append(files[i].name, files[i]);
    }
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseText) {

            window.location.reload();
        }
    };
    xhr.open('POST', "customerDocuments.aspx");
    xhr.send(data);

这是我的代码隐藏文件

中的代码
protected void UploadFile(object sender, EventArgs e)
{
    HttpFileCollection fileCollection = Request.Files;

    for (int i = 0; i < fileCollection.Count; i++)
    {
        HttpPostedFile upload = fileCollection[i];
        string filename = upload.FileName;
        string newFileName = Regex.Replace(filename, " ", "_");

        if (!filename.Equals(""))
        {
            if (newFileName.IndexOf('\\') > -1)
            {
                newFileName = Session["path"].ToString() + newFileName.Substring(newFileName.LastIndexOf('\\') + 1);
            }
            else if (newFileName.IndexOf('/') > -1)
            {
                newFileName = Session["path"].ToString() + newFileName.Substring(newFileName.LastIndexOf('/') + 1);
            }
            else
            {
                newFileName = Session["path"].ToString() + newFileName;
            }

            upload.SaveAs(newFileName);
        }           
    }
}

0 个答案:

没有答案