调用C#函数立即文件文件上传选择 [英] calling C# function immediately file is selected in fileupload
本文介绍了调用C#函数立即文件文件上传选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我使用上传文件,网页表单(asp.net)。在目前的情况下,如果用户选择从他的电脑的文本文件,他有点击一个按钮移到在一个盒子里上传thetext。我试图找到一种方式来跳过一个按钮pressing的步骤。
I have a web form(asp.net) which I'm using to upload file. In current situation if a user choose an text file from his computer he has to click a buttton to upload thetext in a box. I'm trying to find a way to skip the step with a button pressing.
当从用户选择的文件如何调用C#功能?
How to call a C# function when the file is selected from user ?
推荐答案
试试这个
<asp:FileUpload ID="FileUpload01" ClientIDMode="Static" onchange="this.form.submit()" runat="server"/>
在后面的Page_Load事件code
in code behind Page_load event
if (IsPostBack && FileUpload01.PostedFile != null)
{
if (FileUpload01.PostedFile.FileName.Length > 0)
{
FileUpload01.SaveAs(Server.MapPath("~/Images/") + FileUpload01.PostedFile.FileName);
imguser.ImageUrl = "~/Images/" + FileUpload01.PostedFile.FileName;
}
}
这篇关于调用C#函数立即文件文件上传选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文