上传文件在ASP.net不使用的FileUpload服务器控件 [英] Uploading Files in ASP.net without using the FileUpload server control

查看:210
本文介绍了上传文件在ASP.net不使用的FileUpload服务器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到一个ASP.net web表单(V3.5)使用一个普通的老来发布文件<输入类型=文件/>

How can I get an ASP.net web form (v3.5) to post a file using a plain old <input type="file" />?

我没有兴趣使用ASP.net的FileUpload服务器控件。

I am not interested in using the ASP.net FileUpload server control.

感谢您的建议。

推荐答案

在你的aspx:

<form id="form1" runat="server" enctype="multipart/form-data">
 <input type="file" id="myFile" name="myFile" />
 <asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" Text="Upload" />
</form>

在code背后:

protected void btnUploadClick(object sender, EventArgs e)
{
    HttpPostedFile file = Request.Files["myFile"];

    //check file was submitted
    if (file != null && file.ContentLength > 0)
    {
        string fname = Path.GetFileName(file.FileName);
        file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
    }
}

这篇关于上传文件在ASP.net不使用的FileUpload服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆