星空网 > 软件开发 > ASP.net

Asp.net 上传文件小叙(修改FileUpload显示文字等)

想要在asp.net网站上上传文件就得用到FileUpload,可是这个控件中“浏览”没法修改,可以使用html中<input type="file" 来解决该问题。

首先页面不能使用updatepannel,然后需要在页面form中添加method="post" enctype="multipart/form-data" 

例如

 <form id="form1" runat="server" method="post" enctype="multipart/form-data">

然后在页面需要的位置放此代码

<input type="text" id="txtPath" name="txt" style="width:250px" runat="server" /> <input type="button" onmousemove="f.style.pixelLeft=event.x-60;f.style.pixelTop=this.offsetTop;" value="Select" size="30" onclick="f.click()" /> <input type="file" id="f" runat="server" onchange="txtPath.value=this.value" accept="image/gif, image/jpeg" name="f" style="position:absolute;filter:alpha(opacity=0);" size="1" hidefocus="true" />

然后在上传按钮事件中这样写

 1 // 获取客户端上载文件 2 HttpPostedFile UserHPF = Request.Files["f"]; 3 //获取文件夹路径 4 string FilePath = Server.MapPath("./"); 5 string newfilepath = FilePath + "\\" + System.IO.Path.GetFileName(UserHPF.FileName); 6 //将上传的文件存储在指定目录下 7 UserHPF.SaveAs(newfilepath); 8  9 if (File.Exists(newfilepath))10 {11    WebMessageBox(this,"Import license file successfully!");12 }

通过这个方法HttpPostedFile UserHPF = Request.Files["f"];就能取到要上传的文件了 然后就是常规的SaveAs了。

 




原标题:Asp.net 上传文件小叙(修改FileUpload显示文字等)

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

电商培训课程:https://www.goluckyvip.com/tag/30385.html
电商培训内容:https://www.goluckyvip.com/tag/30386.html
电商培训实操:https://www.goluckyvip.com/tag/30388.html
电商培训视频:https://www.goluckyvip.com/tag/30389.html
复盘了上半年:https://www.goluckyvip.com/tag/3039.html
电商培训速成班:https://www.goluckyvip.com/tag/30390.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
南美旅游报价(探索南美洲的旅行费用):https://www.vstour.cn/a/411234.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流