js
function UpladFile() {
var fileObj = document.getElementById("filetes").files[0]; // 獲取文件對象
var FileController = "/Home/upfile"; // 接收上傳文件的后台地址
// FormData 對象
var form = new FormData();
form.append("author", "hooyes"); // 可以增加表單數據
form.append("file", fileObj); // 文件對象
// XMLHttpRequest 對象
var xhr = new XMLHttpRequest();
xhr.open("post", FileController, true);
xhr.onload = function () {
alert("上傳完成!");
};
xhr.send(form);
}
后台
var flist = Request.Files;
for (int i = 0; i < flist.Count; i++)
{
string FilePath = "D:";
var c = flist[i];
FilePath = Path.Combine(FilePath, c.FileName);
c.SaveAs(FilePath);
}