4
I realized it takes one refresh on the full page to get the file from the server side. I would have some way without refresh to perform this operation? I know it’s possible with Ajax, as it would be?
4
I realized it takes one refresh on the full page to get the file from the server side. I would have some way without refresh to perform this operation? I know it’s possible with Ajax, as it would be?
1
I managed using Ajax, I can’t remember where I got the tutorial more my code looked like this:
HTML:
<form role="form" id="commentForm">
<input type="file" id="uploadEditorImage" accept="image/*" />
<button type="button" id="btnEnviar" data-loading-text="Enviando..." class="btn btn-primary">
Enviar
</button>
</form>
Ajax:
$("#btnEnviar").click(function () {
var dataForm = new FormData($("#commentForm")[0]);
var files = $("#uploadEditorImage").get(0).files;
if (files.length > 0) {
dataForm.append("HelpSectionImages", files[0]);
}
$.ajax({
url: '@Url.RouteUrl(new { action = "EnviaArquivo", controller = "Home" })',
type: "POST",
processData: false,
contentType: false,
data: dataForm,
success: function (response) {
console.log('sucesso');
console.log(response);
},
error: function (er) {
console.log('erro');
console.log(er);
}
});
});
Controller:
[WebMethod]
public string EnviaArquivo(FormCollection form)
{
HttpPostedFile arquivo = System.Web.HttpContext.Current.Request.Files["HelpSectionImages"];
string path = "~/img/fotosDepoimentos/";
arquivo.SaveAs(Server.MapPath(path + arquivo.FileName));
return "Arquivo enviado com sucesso...";
}
0
The way I always recommend is using ajaxuploader, it is free and very easy to use.
note: not microsoft ajax
link to the project
http://ajaxuploader.com/default.htm
how to implement http://ajaxuploader.com/Deployment.htm
P/ me that was free, is that only sent me here in the company, where you saw that you are paid?
http://ajaxuploader.com/download.htm. says he gets paid after 30 days.
-1
The problem is because an Asyncpostback is occurring, and to send the file must be a common Postback. So, just add a Postbacktrigger force the Updatepanel update.
Assuming there is a "Send" button inside the Updatepanel, try:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="EnviarBtn" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="EnviarBtn" runat="server" />
More information:
Browser other questions tagged asp.net file-upload webforms
You are not signed in. Login or sign up in order to post.
Could Marconi put some code you made relative to the question? So people can help you in a better way.
– Flávio Granato
Reopened, welcome answers.
– Sergio