Senhores bom dia,
Gostaria de uma ajuda,como faço para pegar no code behind o valor de um FileUpload?
No meu caso está indo null, poderiam me dar um help?
$(function () {
$("#aviso").fadeIn("slow");
$("#btnLogin").click(function () {
var file = new FormData();
var files = $("#fileUpload").get(0).files;
// Add the uploaded image content to the form data collection
if (files.length > 0) {
file.append("UploadedImage", files[0]);
}
var login = $("#txtNome").val();
var senha = $("#txtSenha").val();
$.ajax({
type: "POST",
url: "Default.aspx/Login",
data: "{login: '" + login + "', senha: '" + senha + "', file: '" + files[0] + "'}",
contentType: "application/json; charset=utf-8",
success: function (data) {
$("#resposta").text(data.d);
},
error: function (data) {
$("#resposta").text(data.d);
}
});
return false;
});
});
[WebMethod]
public static string Login(string login, string senha, object file)
{
string resposta = "";
var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];
if (httpPostedFile != null)
{
var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), httpPostedFile.FileName);
// Save the uploaded file to "UploadedFiles" folder
httpPostedFile.SaveAs(fileSavePath);
}
if (login == "admin" && senha == "admin")
{
resposta = "Login aceito";
}
else
{
resposta = "Login/Senha inválidos";
}
return resposta;
}